default userpic

scope and use of variables in templates & templates working mechanism

Vote 0 Votes

I have a long explanation related with my questions. You can skip them and jump to the generalized questions.

I am creating a web page with a purpose different than blogging. It is like a technical terms dictionary in Japanese. An entry under a category corresponds to a technical term.

The page has a 3 columns layout (beta-alpha-gamma). Gamma includes the list of categories. Beta includes the list of entries of a category whose entry is displayed.

If I click to a category in the gamma column, only its first entry is to be displayed. Also, if I click to an entry in the beta column, only that entry is to be displayed.

When the start page is loaded, alphabetically first entry of a preset category (like "

At first, I created a template module, "sidebars", listing the categories and related entries in the columns and called it from the "footer" module. I defined a variable, "disp_cat", to hold the value of displayed category in main index, some other templates and header module.

Start page is loaded very well. When I click to any link (category, entry, title of the entry, link to other entries in the displayed entry), the page loaded shows the first entry, but gamma and beta columns don't list the correct titles and a group of entries (pelase see below for a piece of related code) are not displayed. Unless I access to the start page, the problem remains same in any page loaded. It seemed to me that the module "sidebars" in a strange way when I access to archive pages.

               <mt:Entries id="2648">
                   <a href="<$mtEntryPermalink$>"><$mtEntryTitle$></a>
               </mt:Entries> 


I couldn't solve it. I created index templates (sidebarx1, etc) for each bunch of code in the "sidebars" module, and I called them through "include" tag. The loaded page doesn't have similar problems described above, but the code for the beta column doesn't filter entries to create a list for the clicked category name. It seems "disp_cat" variable is not a variable for index templates. I couldn't pass it to the index templates (sidebarx1...). A piece of code in the index template(sidebarx1), given in question #3 below, shows the use of this variable. Its value is assigned in the template module (sidebars).


####

My questions are as follows:

1. What should I do to see the same special entry list in the sidebar of the start page, on an archive page when I clicked to a link taking me that page? Simply, how a can I keep the customized(?) contents of sidebars in any page?

2. Can I pass a variable, which is also used in other templates, to an index template? If I can, how?

3. What is the working mechanism of templates? I mean, why does an archive page treat a module (or a bunch of code in a sidebar, please see below for an example) different than the main page treats? This is very basic, but I cannot figure out the mapping mechanism behind MT. It appears me as a black box. I try to identify the things by trial and error. I highly appreciate if someone could show me any source or explain.

        <div id="beta_bottom">
            <MTEntries category="$disp_cat">
                <br/><a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a>
            </MTEntries>
        </div>

4. What is the best way to have a variable with a global scope? I want any change of its value to be up-to-date whenever the variable is called.

Reported on Movable Type 4.2

3 Replies

| Add a Reply
  • Installed MT. Blog available at http://domain.com/mt.
    How to make a blog that was available at http://domain.com/?

    And do not affect whether this change in the future if the need arises to create another blog in the subdomain?

  • Installed MT. Blog available at http://domain.com/mt.
    How to make a blog that was available at http://domain.com/?

    And do not affect whether this change in the future if the need arises to create another blog in the subdomain?

    • Hi.

      You need to set the settings to the blog under Preferences. You do that for any new blog that you create, as long as the path and the url point to the place were you want you blog it will be as you want it to be. We have mt installed under a subfolder and have ceveral blogs in both subdomains, subfolder and even a different domain on the same server.

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1773 6162

Last Topic: Excluding categories from blog by kholechek on Feb 9, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1429 5077

Last Topic: What apocalypse hit this community in the middle of 2011? by 75th on Feb 10, 2012

695 2910

Last Topic: Insert Image / File Fails by Russ Miller on Feb 10, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

173 737

Last Topic: About the MT version stated in HTML source by Alex E. Schneider on Feb 7, 2012

190 567

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012