Hi
Using CMSMS 1.11.1 & PHP 5.3
I have a template which calls a static file like this:
{include file="/path_to/my_template.tpl"}
In my_template.tpl I assign my content block to variables:
{content assign="mainContent"} which I then reference elsewhere. The placement of this is at the top of the body or above the head, so the variables should be available for the body and head regions.
When editing a page using this template, all the content blocks are appearing as expected. However, when viewing the page in the front end, none of the stored content is displayed.
Using {get_content_vars} it shows that the assigned variables are all there - they just aren't being displayed when referenced in my_template.tpl
If I don't 'assign' the content blocks, then it all works fine.
If I call a separate template first that just sets up the content blocks, all works fine - such as:
{include file="/path_to/set_up_my_content_blocks.tpl"}
{include file="/path_to/my_template.tpl"}
Is this a bug, or is it just the way smarty3 works?
Many thanks
Nik
Assigned content not appearing on an included template
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: Assigned content not appearing on an included template
Two people just tested this on CMSMS 1.11.1 and on the latest svn version and could not reproduce this issue.
The assigned content blocks worked fine for us.
The assigned content blocks worked fine for us.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: Assigned content not appearing on an included template
Thanks Robert
This was a relatively fresh install with only a few additions.
I will do some more testing on a totally fresh install and report back.
In case it wasnt clear - the entire page content was in the external template. There was only the link to the external template in the back end field.
Thanks for your time.
Regards
Nik
This was a relatively fresh install with only a few additions.
I will do some more testing on a totally fresh install and report back.
In case it wasnt clear - the entire page content was in the external template. There was only the link to the external template in the back end field.
Thanks for your time.
Regards
Nik
Re: Assigned content not appearing on an included template
Hi again Robert
I have installed a totally fresh version of 1.11.1 onto a different server.
PHP Version 5.3.10
Without doing anything else, I have created an external template based on the default provided.
In the body, I have put:
{content assign="MainContent"}
{$MainContent}
I then created a new template through cmsms and removed all the code, replacing it with a link to the external template thus:
{include file="/path_to/test.tpl"} and submitted it.
I then created a new page based on this template. I put some text in the 'content' field and submitted it.
When viewing the page on the front end, the variable {$MainContent} is still not shown - as per my earlier post.
ADDENDUM the following only worked when logged in (silly me):
----Entering a {get_template_vars} into the external template shows that the variable $MainContent exists. And subsequently accessing the variable back in the parent template works.-------
here is the result:
http://templatetest.odchost.co.uk/
Many thanks
Nik
I have installed a totally fresh version of 1.11.1 onto a different server.
PHP Version 5.3.10
Without doing anything else, I have created an external template based on the default provided.
In the body, I have put:
{content assign="MainContent"}
{$MainContent}
I then created a new template through cmsms and removed all the code, replacing it with a link to the external template thus:
{include file="/path_to/test.tpl"} and submitted it.
I then created a new page based on this template. I put some text in the 'content' field and submitted it.
When viewing the page on the front end, the variable {$MainContent} is still not shown - as per my earlier post.
ADDENDUM the following only worked when logged in (silly me):
----Entering a {get_template_vars} into the external template shows that the variable $MainContent exists. And subsequently accessing the variable back in the parent template works.-------
here is the result:
http://templatetest.odchost.co.uk/
Many thanks
Nik
Re: Assigned content not appearing on an included template
does
{content assign="MainContent"}
{$MainContent nocache}
make a difference?
{content assign="MainContent"}
{$MainContent nocache}
make a difference?
Re: Assigned content not appearing on an included template
Yes - this does make a difference thanks.
However - on initial inspection, the preview isn't showing those content blocks, nor can I get the 'pagedata' (as in {process_pagedata}) to update without clearing the cache - even with {nocache}{/nocache} applied.
I think I need to do more experimenting I think.
Regards
Nik
However - on initial inspection, the preview isn't showing those content blocks, nor can I get the 'pagedata' (as in {process_pagedata}) to update without clearing the cache - even with {nocache}{/nocache} applied.
I think I need to do more experimenting I think.
Regards
Nik
Re: Assigned content not appearing on an included template
Yes - still struggling with assigning a variable for access in the page using {process_pagedata}.
If I clear the cache, the pagedata is processed, however if I then make a change to the variable in pagedata, it disappears on the front end. Only clearing the cache will make it appear again.
{process_pagedata nocache} and {nocache}{process_pagedata}{/nocache} makes no difference. If I try and access the variable with nocache it makes no difference.
Hmmmm - perhaps the only option is to just turn off smarty caching and accept the longer page loads!
N
If I clear the cache, the pagedata is processed, however if I then make a change to the variable in pagedata, it disappears on the front end. Only clearing the cache will make it appear again.
{process_pagedata nocache} and {nocache}{process_pagedata}{/nocache} makes no difference. If I try and access the variable with nocache it makes no difference.
Hmmmm - perhaps the only option is to just turn off smarty caching and accept the longer page loads!
N
Re: Assigned content not appearing on an included template
I think my issues are somewhat to do with variable scoping in Smarty3.
I found this below on the smarty forum - hope it helps others. I hadn't seen the 'scope=parent' before.
I found this below on the smarty forum - hope it helps others. I hadn't seen the 'scope=parent' before.
In Smarty 3 variables have a scope.
Subtemplates included with the {include} can read all variables which are known in the calling (parent) template. There is just on exception that the special smarty variables $smarty.foreach... and $smarty.section.... are only know within the template where the loops are defined.
If a variable gets assign (written) in a subtemplate its value has by default local scope. So if you read in a subtemplate a variable which is defined in the calling template and modify it, the new value is only known in the subtemplate. The calling template still keeps its original value.
You can overwrite the default scope when you assign a value in the subtemplate. For example:
{assign var=foo value=0 scope=parent} or {$foo=0 scope=parent}
In this case the new value of $foo can also be seen in the calling (parent) template.