[solved]Add tags 2 template for specific pages/exclude pages

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
ladyr0gue
Forum Members
Forum Members
Posts: 91
Joined: Fri Feb 17, 2012 4:25 pm

[solved]Add tags 2 template for specific pages/exclude pages

Post by ladyr0gue »

Hi
My template applies to most of my site
On some pages I have put in the content section dynamic content tags like {news} and {FormBuilder form='contact'} for the contact form and news summary which I don't want to be editable by my client, and I don't want them to appear on every page, just on specific pages.
So should I create a copy of my template for each page with these kinds of items and edit each accordingly? or just tell the user not to delete the tags... or is there a simple way in which I can insert the tags into the main template and have them only appear on specified pages?
Last edited by ladyr0gue on Sun Apr 22, 2012 2:19 pm, edited 3 times in total.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1973
Joined: Mon Jan 29, 2007 4:47 pm

Re: Is there a way to add tags to template for specific page

Post by Jo Morg »

Unless I have some very specific need for multiple templates, I usually use one template with some smarty logic to identify the page (either by alias, by parent or by a smarty variable the page editor can set from the page editor itself). So I just have to check if a condition is met to show or not some section of content.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
mcDavid
Power Poster
Power Poster
Posts: 377
Joined: Tue Mar 31, 2009 8:45 pm

Re: Is there a way to add tags to template for specific page

Post by mcDavid »

you can use the permissions system for this.
remove the "manage all content" permission from the user group of the editor, and manually add the editor on every page he is allowed to edit, but not on the page with the tags.
ladyr0gue
Forum Members
Forum Members
Posts: 91
Joined: Fri Feb 17, 2012 4:25 pm

Re: Is there a way to add tags to template for specific page

Post by ladyr0gue »

Thanks for your replies,
I think I need to use the first option as I want the user to be able to edit content on those pages, just not to accidentally delete the tags. On other pages in the same div we may wish to add editable content.
Please can you tell me how I should specify page alias/es in my template, for example to make the {news} summary to appear on pages alias1 and alias2?
Thanks
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1973
Joined: Mon Jan 29, 2007 4:47 pm

Re: Is there a way to add tags to template for specific page

Post by Jo Morg »

To get the current page alias use {$page_alias}
I saw someone post this code snippet which I believe should work:

Code: Select all

{if page alias="news"}
{news browsecat=1} {* this may be any content you wish *}
{else}
{menu} {* this may be any content you wish *}
{/if}
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Is there a way to add tags to template for specific page

Post by Dr.CSS »

If you are going to be putting the modules calls, {news}, in the same place on every page but want to let the editor change content in Content: box you can...

{content block='modules' label='This box is for module calls only, no other text etc.' oneline='true'}

This will give you a one line edit box you can put the module call in...

This box is for module calls only, no other text etc.:
[ {FormBuilder form='contact'} ]

Pretend there is an edit box around the formbuilder call ;)...
ladyr0gue
Forum Members
Forum Members
Posts: 91
Joined: Fri Feb 17, 2012 4:25 pm

Re: Is there a way to add tags to template for specific page

Post by ladyr0gue »

oh fantastic, thanks, will try that. The prevous solution didn't work for me (though thanks for the reply) and this one was more what I was looking for :D

edit: Yes, can confirm that works a treat, thanks again :)
ladyr0gue
Forum Members
Forum Members
Posts: 91
Joined: Fri Feb 17, 2012 4:25 pm

Re: [solved] how to add tags to template for specific pages?

Post by ladyr0gue »

Just one thing - I noticed that using the

Code: Select all

 {content block='modules' label='This box is for module calls only, no other text etc.' oneline='true'}
actually seems to mean that the page loads the module every time - which on pages like news and contact means that in certain situations it gets doubled up - eg. as news is the default page to display detail when you click on category you get title>categories>summary articles and then the module is called again so title>categories>number of articles called. And on contact page I noticed that this becomes a problem too when you fail to enter all the required fields the contact from reloads in the same page but with another below it. This doesn't happen when you enter the module call into a normal content block, it all beganves as it should. so maybe I'll try creating a oneline content block and labelling it to not be edited :)
ladyr0gue
Forum Members
Forum Members
Posts: 91
Joined: Fri Feb 17, 2012 4:25 pm

Re: how to add tags to template for specific pages?

Post by ladyr0gue »

Ok what I have decided to do now is to have the news module tag in the template so that it appears in the sidebar of every page - the only thing is i would like to have it not appear on the actual News page as of course that page contains the detail view so doesn't need the summary view. have tried excludeprefix but it doesn't like it. How do I create a tag that calls a module in every page except specific aliases? I tried replacing the {news} tag (which works) with a modification of the code Jo found for me...
Jo Morg wrote: {if page alias="news"}
{news browsecat=1} {* this may be any content you wish *}
{else}
{menu} {* this may be any content you wish *}
{/if}
to

Code: Select all

{if page alias="news"}
{content block="some content"}
{else}
{news}
{/if}
but again it didn't work - I get the error
string(114) "Smarty error: [in tpl_body:23 line 6]: syntax error: unidentified token '=' (Smarty_Compiler.class.php, line 1410)"
Parse error: parse error in C:\xampp\htdocs\cmsms\tmp\templates_c\%%01^013^01360D26%%tpl_body%3A23.php on line 13
so can anyone please tell me how to get a news module how to show up on every page but one without adding it to each page manually?

???
ladyr0gue
Forum Members
Forum Members
Posts: 91
Joined: Fri Feb 17, 2012 4:25 pm

Re: Add tags to template for specific pages/ exclude pages

Post by ladyr0gue »

have also tried

Code: Select all

{if $page_news}
{content block="some content"}
{else}
{news}
{/if}
which doesn't throw up any errors, but it doesn't work exactly - news summary still displays on the news page and while this code adds a box named 'some content', it's on every page not just news - and content put in this box doesn't display.

Code: Select all

{if page_news}
{content block="some content"}
{else}
{news}
{/if}
has kinda the opposite effect -the 'some content' clock appears on every page and shows up, but no news anywhere! I think I'm getting closer.. but would appreciate some pointers :)
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1973
Joined: Mon Jan 29, 2007 4:47 pm

Re: Add tags to template for specific pages/ exclude pages

Post by Jo Morg »

I didn't saw this before: there was a typo on my sample....

Code: Select all

{if page alias="news"}
should be

Code: Select all

{if $page_alias="news"}
I apologize for that... :)

IIRC $page_alias should exist on all page templates.

About your sample: {if $page_news} tests if $page_news is True;
You can also test for isset to check if the var exists at all (which, AFAIK, would fail a simple true false test).
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
ladyr0gue
Forum Members
Forum Members
Posts: 91
Joined: Fri Feb 17, 2012 4:25 pm

Re: Add tags to template for specific pages/ exclude pages

Post by ladyr0gue »

Thank you for your reply, but oh dear, I still seem to be failing!

Code: Select all

{if $page_alias="news"}
{content block='some content'}
{else}
{news number="1"}
{/if}
displays the 'some content' content block on every page and no display of news

and smarty error

Code: Select all

string(114) "Smarty error: [in tpl_body:23 line 6]: syntax error: unidentified token '=' (Smarty_Compiler.class.php, line 1410)" 
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Add tags to template for specific pages/ exclude pages

Post by Dr.CSS »

Try using single quotes 'news' in the if page alias=...
ladyr0gue
Forum Members
Forum Members
Posts: 91
Joined: Fri Feb 17, 2012 4:25 pm

Re: Add tags to template for specific pages/ exclude pages

Post by ladyr0gue »

Thanks for keeping up with me on this!

that gives me a smarty error on the news page
string(114) "Smarty error: [in tpl_body:23 line 7]: syntax error: unidentified token '=' (Smarty_Compiler.class.php, line 1410)"
and the same thing. tried the simple quotes on the content block and in the news tag but no - it just doesn't like the '=' :(
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Add tags to template for specific pages/ exclude pages

Post by Dr.CSS »

Sorry...

{if $page_alias == 'news'}

http://www.smarty.net/docsv2/en/languag ... ion.if.tpl
Post Reply

Return to “CMSMS Core”