• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS made Simple Czech Site Zur deutschsprachigen Supportseite Site francophone Sitio en Castellano CMSMS - Magyarország CMSMS -  ???????
Pages: [1] 2
  Print  
Author Topic: Customizing your template based on the current page  (Read 34676 times)
0 Members and 1 Guest are viewing this topic.
calguy1000
CMS GURU - 2nd Tier Support.
Dev Team Member
Power Poster
*****

Karma: 162
Offline Offline

Posts: 5108

Gravatar

Second Tier support


WWW
« on: 23 Apr 2007, 23:33 »

Hi all.  This has been asked recently, and well.... I was finally fooling around with my own personal site, and encountered a need for this functionality.

What I wanted to do, was use one page template for as much as possible, without having numerous similar templates lying around.   However, on my change settings page for FEU, I did not want to have search capabiliteis.  Similarly, on my 'forgot password' page, I did not want to have the login stuff showing up.  Here's what I did to work around the problem.

a) When editing a page, under the options tab (CMS 1.0.5) is a metadata field, where you can entere various meta tags,
    etc, etc.  On my change settings page, I added a few strings like:
Code:
{assign var='hidefeu' value='1'}
{assign var='hidesearch' value='1'}
{assign var='privatepage' value='1'}

b) I marked this page as 'not cachable' (i.e.: I cleared the checkbox in the options tab when editing the page).

c) In my page template, I could then use smarty logic to control wether certain parts of my template were displayed.  In the example below, I can hide the call to the FrontEndUsers module.  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.

Additionally, I can hide page content, if the page is marked as private and theuser is not loggedin.  However, if the page is not marked as private, then the content is displayed.

For example:
Code:
      {if !isset($hidefeu)}
         <div class="login">{cms_module module='FrontEndUsers'  nocaptcha='1'}</div><!-- end of feu -->
      {/if}
      {if $customcontent_loggedin > 0 && !isset($hidesearch)}
         <div class="search">{search}</div><!-- end of search -->
      {/if}

      <!-- Start Content Area -->
      <div id="main">
        {if isset($privatepage)}
           {if $customcontent_loggedin > 0}
              {content}
           {else}
               <div class="bigerror">Private Content.  Authorization Required</div>
           {/if}
        {else}
            {content}
        {/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 (for the private content) used the FrontEndUsers and CustomContent modules.
« Last Edit: 23 Sep 2008, 17:03 by reneh » Logged

Follow me on twitter
For quality help follow these instructions:
a) Think about the problem for an hour
b) research the problem for an hour
c) spend 1/2 an hour explaining it and providing as much information as you can muster
(too much information is okay, not enough information may get your question ignored).
--
if you can't bother explaining your problem well, why should we bother helping with it.
----------------
Don't make me angry..... you won't like me when I'm angry....
Nullig
Power Poster
***

Karma: 67
Offline Offline

Posts: 2215



« Reply #1 on: 24 Apr 2007, 10:52 »

Excellent! This is SO helpful.

Thanks,
Nullig
Logged

Come play in the Sandbox at my CMS Made Simple demo site: http://www.cmsmsdemo.com.
calguy1000
CMS GURU - 2nd Tier Support.
Dev Team Member
Power Poster
*****

Karma: 162
Offline Offline

Posts: 5108

Gravatar

Second Tier support


WWW
« Reply #2 on: 24 Apr 2007, 13:04 »

When working with multiple groups in FEU the problem got a bit more complex.  I wanted the following setup:

i) A group of pages for public/anonymous users
ii) A group of pages for members of group1 (that public/anonymous users could not see)
iii) A group of pages for members of group2
iv) the possibility that a particular user may be a member of both group1 and group2
v) The menu to behave properly for the above conditions.

And.... I didn't want anybody that was not logged in to be able to jump directly to a private page and see it's content.
Here's what I came up with:

in my pages that I wanted private to members of group1
a) set the page alias to group1_<something>
b) set the following code in the metadata field of the options tab:
Code:
{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}

c) Modified my menu call like this
    (this is not complete, as it doesn't achieve step v above, but I'm working on it)
Code:
         
{if $customcontent_loggedin > 0}
            {if isset($customcontent_memberof_group1)}
               {cms_module module='menumanager' template='andreas01 : andreasmenu'   collapse="1" number_of_levels='2' excludeprefix='group2_'}
            {else}
               {cms_module module='menumanager' template='andreas01 : andreasmenu'   collapse="1" number_of_levels='2' excludeprefix='group1_'}
            {/if}
         {else}
            {cms_module module='menumanager' template='andreas01 : andreasmenu'   collapse='1' number_of_levels='2' includeprefix='public_'}
         {/if}

d) Modified my content code like this:
Code:
        {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}

So now I'm almost there.  the only problem I have is if a user is a member of group1 and group2, some pages would be hidden.  This problem could be worked around using a template that had two menus, but I don't want that.  so I'll sleep on it again and see what I can come up with.

Note, that this logic can work in conjunction with the 'hidesearch' stuff I did above, and works well by the way.
« Last Edit: 24 Apr 2007, 13:07 by calguy1000 » Logged

Follow me on twitter
For quality help follow these instructions:
a) Think about the problem for an hour
b) research the problem for an hour
c) spend 1/2 an hour explaining it and providing as much information as you can muster
(too much information is okay, not enough information may get your question ignored).
--
if you can't bother explaining your problem well, why should we bother helping with it.
----------------
Don't make me angry..... you won't like me when I'm angry....
calguy1000
CMS GURU - 2nd Tier Support.
Dev Team Member
Power Poster
*****

Karma: 162
Offline Offline

Posts: 5108

Gravatar

Second Tier support


WWW
« Reply #3 on: 24 Apr 2007, 13:59 »

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:
{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:
$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:
         {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:
       {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.
Logged

Follow me on twitter
For quality help follow these instructions:
a) Think about the problem for an hour
b) research the problem for an hour
c) spend 1/2 an hour explaining it and providing as much information as you can muster
(too much information is okay, not enough information may get your question ignored).
--
if you can't bother explaining your problem well, why should we bother helping with it.
----------------
Don't make me angry..... you won't like me when I'm angry....
calguy1000
CMS GURU - 2nd Tier Support.
Dev Team Member
Power Poster
*****

Karma: 162
Offline Offline

Posts: 5108

Gravatar

Second Tier support


WWW
« Reply #4 on: 26 Apr 2007, 11:14 »

Okay, continuing on this thread..... my next goal was to display the news article title in the titlebar of the detail page, without modifying any source..... and I got it:

Here's how:
1.  In your news detail template add this line:
Code:
{assign var="pagetitle" value=$entry->title}

2.  Move the call to the news summary to the top of your page template (directly above the metadata tag), and surround it with a capture, like this:
Code:
{capture assign='newssummary'}
{cms_module module="news" number="3" summarytemplate='summary2.tpl' detailpage='details'}
{/capture}

3.  In the spot where you had the news tag, replace it with:
Code:
{$newssummary}

4. Move the call to {content} to the top of the page template and surround it with a capture, like this:
Code:
{capture assign='dfltcontent'}{content}{/capture}

5. In the spot where you had {content}, replace it with
Code:
{$dfltcontent}

6. Add this little bit of logic directly below the logic from step 4
Code:
{if !isset($pagetitle)}
{capture assign='pagetitle'}{title}{/capture}
{/if}

7.  In your template, replace any call to {title} with
Code:
{$pagetitle}

i.e:
Code:
<title>{sitename} - {$pagetitle}</title>

And there you are.  Now, when I click on the more link of a news summary item, when the detail page is loaded, it shows the news article title in the frame at the top of the window, and in the page header area.

I've pasted my entire template here as a reference

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

{capture assign='newssummary'}
{cms_module module="news" number="3" summarytemplate='summary2.tpl' detailpage='details'}
{/capture}
{capture assign='dfltcontent'}{content}{/capture}
<!-- title-->
{if !isset($pagetitle)}
{capture assign='pagetitle'}{title}{/capture}
{/if}
<title>{sitename} - {$pagetitle}</title>

{metadata}
{stylesheet}

{cms_selflink dir="start" rellink=1}
{cms_selflink dir="prev" rellink=1}
{cms_selflink dir="next" rellink=1}

</head>

<body>

<div id="wrap">

    <!-- start accessibility skip links -->
    <ul class="accessibility">
      <li><a href="#menu_vert" accesskey="s" title="Skip to navigation">Skip to navigation</a></li>
      <li><a href="#main">Skip to content</a></li>
    </ul>
    <!-- end accessibility skip links -->

   <!-- Start Header, with logo image that links to the default start page -->
   <div id="header" class="clearfix">
        <img class="logo"  src="images/logo.jpg" alt="The Campbell Family Crest" />
           <h1>{sitename}</h1>
<blockquote><div>"Ne Obliviscaris"<br />(Never Forget)</div></blockquote>
<h2>{$pagetitle}</h2>
   </div>
   <!-- End Header -->

      <!-- Start Vertical Navigation -->
      <div id="avmenu">
         <h2 class="accessibility">Menu:</h2>
         {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}

<div class="announce">
{$newssummary}
</div>
{global_content name='calgary_weather'}

      </div>
      <!-- End Horizontal Navigation -->

 
   <!-- Start Breadcrumbs -->
<!--
Breadcrumbs is hidden for now
   <div class="breadcrumbs">
        {breadcrumbs starttext='You are here' root='Home' delimiter='&raquo;'}
   </div>
-->
   <!-- End Breadcrumbs -->

   <!-- Start Content (Navigation and Content columns) -->
   <div id="content" class="clearfix">

      <div id="topbar">
      {if !isset($hidefeu)}
         <div class="login">{cms_module module='FrontEndUsers'  nocaptcha='1'}</div><br/><!-- end of feu -->
      {/if}
      {if $customcontent_loggedin > 0 && !isset($hidesearch)}
         <div class="search">{search}</div><br/><!-- end of search -->
      {/if}
      </div>

      <!-- Start Content Area -->
      <div id="main">
        {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'}
           {$dfltcontent}
        {else}
            <div class="bigerror">Private Content.  Authorization Required</div>
        {/if}


         <!-- Start relational links -->
<!-- hidden
<div class="hr"></div>
<div class="right49">
<p><a href="#main">^ Top</a></p>
</div>
         <div class="left49">
            <p>{cms_selflink dir="previous"} <br />
            {cms_selflink dir="next"}</p>
         </div>
-->
<!-- End relational links -->
 
      </div>
  <!-- End Content Area -->

   </div>
   <!-- End Content -->

   <!-- Start Footer -->
   <div id="footer" class="clearfix">
Copyright &copy; 2005 (Robert Campbell). Original Design by <a href="http://andreasviklund.com">Andreas Viklund</a>.<br/>
Powered by <a href="http://www.cmsmadesimple.org">{image src="cmsbadge2.png" alt="CMS Made Simple"}</a>&nbsp;{cms_version}
   </div>
   <!-- End Footer -->


</div><!-- end wrap -->


</body>
</html>

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

Follow me on twitter
For quality help follow these instructions:
a) Think about the problem for an hour
b) research the problem for an hour
c) spend 1/2 an hour explaining it and providing as much information as you can muster
(too much information is okay, not enough information may get your question ignored).
--
if you can't bother explaining your problem well, why should we bother helping with it.
----------------
Don't make me angry..... you won't like me when I'm angry....
marvanni
Guest
« Reply #5 on: 03 May 2007, 08:12 »


Steps:
1.  In the metadata field of each of your private pages, add code similar to this: (change your group names as required)
Code:
{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 tried this and works quite well. I wonderd if it is possible to create a user defined tag from
Code:
{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}

When i try this i get an error.

It would be much better if in the editting page of the contentitem was a selectbox, where you can set the page private. Is it somehow possible to insert the tag above with a checkbox?
Logged
jsmonzani
Forum Members
**

Karma: 4
Offline Offline

Posts: 42


« Reply #6 on: 07 May 2007, 05:26 »

> I wonderd if it is possible to create a user defined tag from
> When i try this i get an error.

I haven't followed the discussion, but if you paste Smarty code in a User Defined Code, it won't work since it expects PHP. Maybe that's your problem? You can make a global content block instead.
Logged

An approach to mutli-lingual CMSMS using only content blocks:
http://forum.cmsmadesimple.org/index.php/topic,11756.0.html
Russ
Power Poster
***

Karma: 3
Offline Offline

Posts: 797


Find out how we can make your ideas shine...


WWW
« Reply #7 on: 02 Jul 2007, 07:48 »

Okay, continuing on this thread..... my next goal was to display the news article title in the titlebar of the detail page, without modifying any source..... and I got it:

First off very nice calguy1000, but at least in 1.1 RC3 /News 2.3.0.1 they can be a few problems with RSS and Search.

If you have a url something like: http://domain.dev/news/1/82/
Where '1' is the news article and '82' is the news page id. (Using friendly URL's.) 

1. RSS Failure
This fails in RSS feeds because it returns:
http://domain.dev/news/1
without the /82/. The 'current page' also appears to be home - which is also going to confuse many people and is pretty bad on the accessibility front.

If you alter the RSS template from this:
<link>{$entry->link}</link>
to this:
<link>{$entry->link}82</link>
It will work OK, and returns
http://domain.dev/news/1/82/

But obviously this is not a real solution as it requires a fixed id!

2. Search failure
Exactly the same happens with Search - although I have not found a way to fix this?

3. On a completely different subject, is there a way to have a url, like date/category/article_title. I know there used to be, but it doesn't look like it would work in the current version?

I have posted a bug report for this as it makes it quite inaccessible - if fixed of course news would become quite accessible!

Russ
Logged

shoes for industry - a small consultancy who do a surprising number of things surprisingly well.
http://www.shoesforindustry.net/
FantomCircuit
Forum Members
**

Karma: 1
Offline Offline

Posts: 75


The Toast King


« Reply #8 on: 21 Jul 2007, 23:32 »

great idea!

This should help me, as before I was using mutiple content blocks and modifying the content for each page of my site - this method should keep it much more tidy.
Logged
JoeGrinD
Forum Members
**

Karma: 0
Offline Offline

Posts: 15


« Reply #9 on: 01 Aug 2007, 14:04 »

I have used something like this on some of my pages for simple inclusion/exclusions:

Code:
{if $page == 'pagename'}
 do something for pagename
{else $page =='anotherpage'}
 do something else for another similar page
{/if}
Logged
moorezilla
Power Poster
***

Karma: 12
Offline Offline

Posts: 305


« Reply #10 on: 05 Sep 2007, 13:57 »

Can this be used if more than one news summary is put into a page? For example, we use the News system for both traditional news and for open teaching positions. We also use the News system to publish student articles, so there are times where we may need to call the news three times on one page. Can we simply have multiple captures in the head of the document, or is this basically designed only for situations where the News system is only called once?

cmsms 1.1.2
php5.2x
apache
mysql5

am
Logged
calguy1000
CMS GURU - 2nd Tier Support.
Dev Team Member
Power Poster
*****

Karma: 162
Offline Offline

Posts: 5108

Gravatar

Second Tier support


WWW
« Reply #11 on: 05 Sep 2007, 14:13 »

You can use capture as much as you want.
Logged

Follow me on twitter
For quality help follow these instructions:
a) Think about the problem for an hour
b) research the problem for an hour
c) spend 1/2 an hour explaining it and providing as much information as you can muster
(too much information is okay, not enough information may get your question ignored).
--
if you can't bother explaining your problem well, why should we bother helping with it.
----------------
Don't make me angry..... you won't like me when I'm angry....
Caspar
Forum Members
**

Karma: 7
Offline Offline

Posts: 111



WWW
« Reply #12 on: 10 Sep 2007, 08:30 »

Code:
{assign var='hidefeu' value='1'}
{assign var='hidesearch' value='1'}
{assign var='privatepage' value='1'}

Hi Calguy,
that's exactly what I need, but I can't get it to work. Here's what I did:
In one of my page's I added options->metadata:
Code:
{assign var='whatever' value='1'}
In the template for that page I added:
Code:
{if !isset($whatever)}<h5>Whatever</h5>{/if}
No effect. No error messages in the source code of the page neither.

I tried the following:
I cleared the cms cache and the browser cache.
I used the global metadata instead of the page's.

Are there any other settings I shoud take care of (config.php or so)?

Thanks!
Caspar
Logged


xhtml: ok, css: ok, javascript: getting better, php: bits of.
sig
Forum Members
**

Karma: 0
Offline Offline

Posts: 10


« Reply #13 on: 10 Sep 2007, 12:18 »

Hi Calguy,
that's exactly what I need, but I can't get it to work. Here's what I did:
In one of my page's I added options->metadata:
Code:
{assign var='whatever' value='1'}
In the template for that page I added:
Code:
{if !isset($whatever)}<h5>Whatever</h5>{/if}
No effect. No error messages in the source code of the page neither.


It's because you have set the value 'whatever' to 1, and it'll be echoed only if it's not set (!isset)

Thus you should use:
Code:
{if isset($whatever)}<h5>Whatever</h5>{/if}

Now as the variable 'whatever' is set, the text 'Whatever' is printed.

Logged
Caspar
Forum Members
**

Karma: 7
Offline Offline

Posts: 111



WWW
« Reply #14 on: 10 Sep 2007, 13:39 »

 Lips sealed (Sorry for being so stupid!)

THANKS!
Caspar
Logged


xhtml: ok, css: ok, javascript: getting better, php: bits of.
Pages: [1] 2
  Print  
 
Jump to: