default userpic

Custom Fields Header

Vote 0 Votes

I am attempting to use custom fields within the header module of the system templates. I am using these custom fields for meta keywords and meta tags and inserting them just after the following line within the header module:

<mt:SetVarBlock name="profile_view_url"><$mt:CGIPath$><$mt:CommunityScript$>?__mode=view&amp;blog_id=<$mt:BlogID encode_html="1"$>&amp;id=</mt:SetVarBlock>

My code looks like this and uses an IF statement to seperate what the index page should do versus all the other pages.

    <mt:Entries>
        <mt:If name="main_index">
            <meta name="keywords" content="home page key words" />
            <meta name="description" content="Home page description" />
        <mt:Else>
            Custom field here
        </mt:If>
    </mt:Entries>

My problem is that when I re-published the site the custom fields for each individual entry only use the data from the most recent entry. I am confused why this would happen? What am I missing? Is the header module only generated once and somehow cached by the system and re-used for the sake of increased performance during publishing. IF so, how do I solve this?

Cheers,

Paul Sveda

4 Replies

| Add a Reply
  • You're seeing this precisely because your template is generated (i.e. interpreted) only once then the result is cached and used as is for generating all pages. Do not cache this template and it should work as intended.

    As a rule of thumb:
    - never cache a template that contains logic depending on things that can vary (e.g. from one entry to another)
    - never use a server-side include (Apache, PHP, etc.) for a template that has MT code in it

  • Hi Francois

    Thank you for the quick reply and the great points.

    Still stuck on the problem though. Under Preferences > Publishing Settings under the Module Option the option for Module Caching is not enabled and servers side includes drop down is set to none (disabled). Am I missing another setting?

    In addition there is no caching option under Global Templates > Header.

    I have also gone ahead and tried to control the cache issue with a tag value like so:

    <$mt:Include module="Header" cache="0" body_class="mt-entry-archive"$>
    

    The templates are all linked to a file. The file does have the PHP extension but I don't see how this would affect it.

    Is the problem the fact that the header module exists as a global template instead of a module template specific to the blog?

    Thanks again for the help.

  • Which module (and code) is linked to a file? Outputting as a file in order to include this file later on will cause the same issues as caching or SSI if it contains MT code that is supposed to vary for each element of a list, for example (it will be generated once then included as is for all the other iterations). I should have added that to my list above.

  • By linked to a file I meant that MT is reading the code from a file on the server as I don't use the MT editor to make changes. I use notepad++ and then put the file on the server and MT updates the code from there. I am NOT generating the file once (like an include) and then linking to that.

    Having said all that, I am still experiencing the problem and stumped.

    Cheers,

    P.

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