Page 2 of 2

Re: Customizing your template based on the current page

Posted: Mon Mar 17, 2008 4:26 am
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.

Re: Customizing your template based on the current page

Posted: Mon Mar 17, 2008 11:06 am
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

Re: Customizing your template based on the current page

Posted: Sat Mar 29, 2008 6:56 pm
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

Re: Customizing your template based on the current page

Posted: Sat Mar 29, 2008 7:01 pm
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.

Re: Customizing your template based on the current page

Posted: Fri Oct 10, 2008 11:11 am
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

Re: Customizing your template based on the current page

Posted: Tue Dec 16, 2008 5:22 am
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()}

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

Posted: Thu Feb 11, 2010 12:01 am
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.

Re: Customizing your template based on the current page

Posted: Thu Feb 11, 2010 12:14 am
by jmcgin51
check this document for more up-to-date info.  (document written by calguy1000)

http://calguy1000.com/uploads/1/Hiding_ ... e-pdf.html

Re: Customizing your template based on the current page

Posted: Thu Feb 11, 2010 5:44 am
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

Re: Customizing your template based on the current page

Posted: Thu Feb 11, 2010 7:53 am
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.

Newbie to CMSMS and need help please.

Posted: Thu Dec 16, 2010 7:23 pm
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

Re: Newbie to CMSMS and need help please.

Posted: Thu Dec 16, 2010 7:51 pm
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