Customizing your template based on the current page

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
hillel213
New Member
New Member
Posts: 4
Joined: Fri Feb 22, 2008 5:52 pm

Re: Customizing your template based on the current page

Post by hillel213 »

I changed my urls to pretty urls; however, when I use the search module, the standard pages work, but the news pages do not show the proper url.

It shows /news/5/53/.  It inserts news instead of the actual news url name.

My search results template is...

Code: Select all

<h3>{$searchresultsfor} "{$phrase}"</h3>
{if $itemcount > 0}
   <ul>
   {foreach from=$results item=entry}
      <li>{$entry->title} - <a href="{$entry->url}">{$entry->urltxt}</a> ({$entry->weight}%)</li>
   {/foreach}
   </ul>

   <p>{$timetaken}: {$timetook}</p>
{else}
   <p><strong>{$noresultsfound}</strong></p>
{/if}


My htacess is

Code: Select all

Options +FollowSymLinks
RewriteEngine on

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# News
RewriteRule ^([A-Za-z0-9-]+)/([0-9]+)/([0-9]+)/?$ index.php?mact=News,cntnt01,detail,0&cntnt01articleid=$2&cntnt01returnid=$3 [L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]


Help.
thoms
Forum Members
Forum Members
Posts: 84
Joined: Tue Dec 25, 2007 5:56 pm

Re: Customizing your template based on the current page

Post by thoms »

calguy1000 wrote:I hope this helps people out, and if you have any questions or comments, I'd be happy to hear them.


It's quite nice and helpful, but the major problem is IMHO that you have to disable caching for ALL your pages that use CC/FEU-logic. Depending on your server, that may cause significant waiting periods on each page view.

Thomas
leslie894

Re: Customizing your template based on the current page

Post by leslie894 »

calguy1000 wrote:As well, I can hide the search form, if the user is not logged in or the search form is not useful on specific pages.
For example:

Code: Select all

      {if $customcontent_loggedin > 0 && !isset($hidesearch)}
         <div class="search">{search}</div><!-- end of search -->
      {/if}


I hope this helps people, particularly those who are just starting with CMSMS.  Or, ar just starting to do conditional logic in their templates.

FYI: The example here used the FrontEndUsers and CustomContent modules.


Calguy,

If the intent was to prevent visitors from searching unless they are logged in, is it not necessary to modify the search templates as well? It's possible for a knowledgeable visitor to create a URL that called your search module and type it in manually in the address bar.

To prevent that I am modifying the search results template to only display data if the user was logged in.

Leslie
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Customizing your template based on the current page

Post by calguy1000 »

Yes, if you were worried about the security of your content you would have to do that.

But  if you're just worried about the way the site looks on certain pages, or for logged in users then you could use this logic.  Otherwise, you'd have to put logic into the search results template too.
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.
AngelEyes
Forum Members
Forum Members
Posts: 23
Joined: Tue Nov 20, 2007 3:42 pm

Re: Customizing your template based on the current page

Post by AngelEyes »

Hi,

Is it possible to make conditional statements based on the alias of the parent page/section?

Code: Select all

{if $page == 'pagename'}
 do something for pagename
{else $page =='anotherpage'}
 do something else for another similar page
{/if}


I understand how the above works but am looking for something that would look something like this I guess:

Code: Select all

{if $parent == 'pagename'}
 do something for pagename
{else $parent =='anotherpage'}
 do something else for another similar page
{/if}


Perhaps there is another way to do this, any help much appreciated.

Thanks,

Adam
JohnnyB
Dev Team Member
Dev Team Member
Posts: 729
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: Customizing your template based on the current page

Post by JohnnyB »

AngelEyes wrote:Hi,

Is it possible to make conditional statements based on the alias of the parent page/section?

Code: Select all

{if $page == 'pagename'}
 do something for pagename
{else $page =='anotherpage'}
 do something else for another similar page
{/if}


I understand how the above works but am looking for something that would look something like this I guess:

Code: Select all

{if $parent == 'pagename'}
 do something for pagename
{else $parent =='anotherpage'}
 do something else for another similar page
{/if}


Perhaps there is another way to do this, any help much appreciated.

Thanks,

Adam


This is an old post, but... this can be done using calguy1000's CG simple smarty module.  Install using the module manager and view the help screen to see how to grab a page parent.

For example, I use this often to get the page root:

{$cgsimple->get_root_alias()}
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
ledut
New Member
New Member
Posts: 2
Joined: Wed Feb 10, 2010 11:55 pm

Re: Multiple User Groups, One Menu, and assuring private access

Post by ledut »

I need to print different menus for different FEU groups :
Does this tip still up to date ??
is there a simpler way to do it using excludeprefix="" parametter ??

calguy1000 wrote:Here it is..... the latest howto as to how I solved this problem.  Here's the scenario:

Two user groups, each requiring independant content
One menu in the template
Users can be a member of both groups

Requirements:
CMS Made Simple 1.0.5 or greater
CustomContent 1.4.4 or Greater
MenuManager 1.4 or Greater
FrontEndUsers (version shouldn't matter much)

Steps:
1.  In the metadata field of each of your private pages, add code similar to this: (change your group names as required)

Code: Select all

{assign var='content_is_visible' value='0'}
{if $customcontent_loggedin > 0}
   {if isset($customcontent_memberof_group1)}
       {assign var='content_is_visible' value='1'}
   {/if}
{/if}


2.  Add this user defined tag, named:  groups_to_prefixes

Code: Select all

$postfix = '_';
if( isset($params['postfix']) )
{
   $postfix = trim($params['postfix']);
}

$adjustcase =1;
if( isset($params['noadjustcase']) )
{
  $adjustcase = 0;
}

if( isset($params['groups']) )
{
   $groups = explode(',',$params['groups']);
   for( $i = 0; $i < count($groups); $i++ )
     {
          if( $groups[$i] != '' )
          {
              if( $adjustcase == 1 )
                 {
                     $groups[$i] = strtolower($groups[$i].$postfix);
                 }
              else
                 {
                     $groups[$i] = $groups[$i].$postfix;
                  }
           }
     }

   return implode(',',$groups);
}
return '';


3.  Adjust your menu call in your template like this:

Code: Select all

         {assign var='includeprefix' value='public_'}
         {if $customcontent_loggedin > 0}
            {capture assign='includeprefix'}{$includeprefix},{groups_to_prefixes groups=$customcontent_groups}{/capture}
         {/if}
         {cms_module module='menumanager' template='andreas01 : andreasmenu'   collapse='1' number_of_levels='2' includeprefix=$includeprefix}


4.  Adjust your content area in your template like this:

Code: Select all

       {if !isset($content_is_visible)}
            {* assume public content, unless the variable is already set *}
            {assign var='content_is_visible' value='1'}
        {/if}
        {if $content_is_visible == '1'}
           {content block='header'}
           {content}
        {else}
            <div class="bigerror">Private Content.  Authorization Required</div>
        {/if}


5. Adjust the page alias of all of your pages as follows:

     Pages that anonymous/non logged in people can see should start with public_
     Pages that only members of group1 can see should begin with group1_   (change group1 to your group name of course)
     Similarly, pages that only members of group2 can see should begin with group2_

Conclusion:
Now, the menu should appear properly for anonymous users as well as for members of group1 and/or group2.  Also, anybody directly accessing a page their not entitled to see, should get the 'Authorization Required' message.

This solution should work for any number of groups, with menu.  I hope this helps everybody.
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: Customizing your template based on the current page

Post by jmcgin51 »

check this document for more up-to-date info.  (document written by calguy1000)

http://calguy1000.com/uploads/1/Hiding_ ... e-pdf.html
ledut
New Member
New Member
Posts: 2
Joined: Wed Feb 10, 2010 11:55 pm

Re: Customizing your template based on the current page

Post by ledut »

I did it  :D Thanks a lot !
I spent time to read the full documentation but it is very interesting.
By the way, I tried the "old way" : it was a failure
gdur
Forum Members
Forum Members
Posts: 142
Joined: Sun Jan 10, 2010 10:59 am

Re: Customizing your template based on the current page

Post by gdur »

I followed this Tip and noticed that I was likely trapped  because of changes from earlier versions of CMSMS (CMS 1.0.5?) and has not been adjusted for the actual version (1.6.6).
In this TIP it is written to put a Smarty tag in the "metadata field" but that doesn't work (anymore?). It needs to be placed in the "Smarty data or logic..." area. It took me quite some time to figure that one out so I hope this will be helpful and time saving for others.
garrick
New Member
New Member
Posts: 3
Joined: Thu Dec 16, 2010 5:05 pm

Newbie to CMSMS and need help please.

Post by garrick »

I am trying to create a members area on a website. I want the private page to show up on the menu when the user correctly logs in.

I meet all of these requirements below:

calguy1000 wrote:
Requirements:
CMS Made Simple 1.0.5 or greater
CustomContent 1.4.4 or Greater
MenuManager 1.4 or Greater
FrontEndUsers (version shouldn't matter much)


In this step I pasted this information into my private page's metadata field and changed this: {if isset($customcontent_memberof_group1)} to this: {if isset($customcontent_memberof_ambassadors}. Which is a group that I had already created and assigned a test user to.
Steps:
1.  In the metadata field of each of your private pages, add code similar to this: (change your group names as required)

Code: Select all

{assign var='content_is_visible' value='0'}
{if $customcontent_loggedin > 0}
   {if isset($customcontent_memberof_group1)}
       {assign var='content_is_visible' value='1'}
   {/if}
{/if}


I created a user defined tag with the code below and named it groups_to_prefixes
2.  Add this user defined tag, named:  groups_to_prefixes

Code: Select all

$postfix = '_';
if( isset($params['postfix']) )
{
   $postfix = trim($params['postfix']);
}

$adjustcase =1;
if( isset($params['noadjustcase']) )
{
  $adjustcase = 0;
}

if( isset($params['groups']) )
{
   $groups = explode(',',$params['groups']);
   for( $i = 0; $i < count($groups); $i++ )
     {
          if( $groups[$i] != '' )
          {
              if( $adjustcase == 1 )
                 {
                     $groups[$i] = strtolower($groups[$i].$postfix);
                 }
              else
                 {
                     $groups[$i] = $groups[$i].$postfix;
                  }
           }
     }

   return implode(',',$groups);
}
return '';



I placed the code below within my template where I want the menu to be. And I changed this: {cms_module module='menumanager' template='andreas01 : andreasmenu'  collapse='1' number_of_levels='2' includeprefix=$includeprefix} to this:  {cms_module module='menumanager' template='header_menu'  collapse='1' number_of_levels='2' includeprefix=$includeprefix} where header_menu is the name of my menu template.

3.  Adjust your menu call in your template like this:

Code: Select all

         {assign var='includeprefix' value='public_'}
         {if $customcontent_loggedin > 0}
            {capture assign='includeprefix'}{$includeprefix},{groups_to_prefixes groups=$customcontent_groups}{/capture}
         {/if}
         {cms_module module='menumanager' template='andreas01 : andreasmenu'   collapse='1' number_of_levels='2' includeprefix=$includeprefix}


I pasted the code blow into the content area of my templates and did not change anything.
4.  Adjust your content area in your template like this:

Code: Select all

       {if !isset($content_is_visible)}
            {* assume public content, unless the variable is already set *}
            {assign var='content_is_visible' value='1'}
        {/if}
        {if $content_is_visible == '1'}
           {content block='header'}
           {content}
        {else}
            <div class="bigerror">Private Content.  Authorization Required</div>
        {/if}



I added public_ to all of my public pages and ambassadors_ to my private page as stated below. Where again ambassadors is my group with the one test user I have created. The public pages show up in my menu and the private page is hidden from the menu when I am not logged in. However, when logged in the private page does not show up in my menu but the public pages still do.

5. Adjust the page alias of all of your pages as follows:
     Pages that anonymous/non logged in people can see should start with public_
     Pages that only members of group1 can see should begin with group1_   (change group1 to your group name of course)
     Similarly, pages that only members of group2 can see should begin with group2_

Conclusion:
Now, the menu should appear properly for anonymous users as well as for members of group1 and/or group2.  Also, anybody directly accessing a page their not entitled to see, should get the 'Authorization Required' message.

This solution should work for any number of groups, with menu.  I hope this helps everybody.


Any help on this would be greatly appreciated. I think I have posted every thing I need to, if not please let me know and I will post it immediately. Thanks
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: Newbie to CMSMS and need help please.

Post by jmcgin51 »

garrick wrote:I am trying to create a members area on a website. I want the private page to show up on the menu when the user correctly logs in.

I meet all of these requirements below:

calguy1000 wrote:
Requirements:
CMS Made Simple 1.0.5 or greater
CustomContent 1.4.4 or Greater
MenuManager 1.4 or Greater
FrontEndUsers (version shouldn't matter much)


In this step I pasted this information into my private page's metadata field and changed this: {if isset($customcontent_memberof_group1)} to this: {if isset($customcontent_memberof_ambassadors}. Which is a group that I had already created and assigned a test user to.
Steps:
1.  In the metadata field of each of your private pages, add code similar to this: (change your group names as required)

Code: Select all

{assign var='content_is_visible' value='0'}
{if $customcontent_loggedin > 0}
   {if isset($customcontent_memberof_group1)}
       {assign var='content_is_visible' value='1'}
   {/if}
{/if}


I created a user defined tag with the code below and named it groups_to_prefixes
2.  Add this user defined tag, named:  groups_to_prefixes

Code: Select all

$postfix = '_';
if( isset($params['postfix']) )
{
   $postfix = trim($params['postfix']);
}

$adjustcase =1;
if( isset($params['noadjustcase']) )
{
  $adjustcase = 0;
}

if( isset($params['groups']) )
{
   $groups = explode(',',$params['groups']);
   for( $i = 0; $i < count($groups); $i++ )
     {
          if( $groups[$i] != '' )
          {
              if( $adjustcase == 1 )
                 {
                     $groups[$i] = strtolower($groups[$i].$postfix);
                 }
              else
                 {
                     $groups[$i] = $groups[$i].$postfix;
                  }
           }
     }

   return implode(',',$groups);
}
return '';



I placed the code below within my template where I want the menu to be. And I changed this: {cms_module module='menumanager' template='andreas01 : andreasmenu'   collapse='1' number_of_levels='2' includeprefix=$includeprefix} to this:  {cms_module module='menumanager' template='header_menu'   collapse='1' number_of_levels='2' includeprefix=$includeprefix} where header_menu is the name of my menu template.

3.  Adjust your menu call in your template like this:

Code: Select all

         {assign var='includeprefix' value='public_'}
         {if $customcontent_loggedin > 0}
            {capture assign='includeprefix'}{$includeprefix},{groups_to_prefixes groups=$customcontent_groups}{/capture}
         {/if}
         {cms_module module='menumanager' template='andreas01 : andreasmenu'   collapse='1' number_of_levels='2' includeprefix=$includeprefix}


I pasted the code blow into the content area of my templates and did not change anything.
4.  Adjust your content area in your template like this:

Code: Select all

       {if !isset($content_is_visible)}
            {* assume public content, unless the variable is already set *}
            {assign var='content_is_visible' value='1'}
        {/if}
        {if $content_is_visible == '1'}
           {content block='header'}
           {content}
        {else}
            <div class="bigerror">Private Content.  Authorization Required</div>
        {/if}



I added public_ to all of my public pages and ambassadors_ to my private page as stated below. Where again ambassadors is my group with the one test user I have created. The public pages show up in my menu and the private page is hidden from the menu when I am not logged in. However, when logged in the private page does not show up in my menu but the public pages still do.

5. Adjust the page alias of all of your pages as follows:
     Pages that anonymous/non logged in people can see should start with public_
     Pages that only members of group1 can see should begin with group1_   (change group1 to your group name of course)
     Similarly, pages that only members of group2 can see should begin with group2_

Conclusion:
Now, the menu should appear properly for anonymous users as well as for members of group1 and/or group2.  Also, anybody directly accessing a page their not entitled to see, should get the 'Authorization Required' message.

This solution should work for any number of groups, with menu.  I hope this helps everybody.


Any help on this would be greatly appreciated. I think I have posted every thing I need to, if not please let me know and I will post it immediately. Thanks

Don't have time to read your full post, but the first thing you need to do is to use the current syntax for CustomContent.  The post you quoted was from 2007, and a lot has changed since then.

This:
{if $customcontent_loggedin > 0}
  {if isset($customcontent_memberof_group1)}


should be
{if $cccuser->loggedin()}
  {if $ccuser->memberof('group1')}


This document would be worth your time:
http://calguy1000.com/uploads/1/Hiding_ ... e-pdf.html
Locked

Return to “Tips and Tricks”