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&blog_id=<$mt:BlogID encode_html="1"$>&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
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:
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.