Page 1 of 1

if ($thispage == "david_snyder") echo " <em>Miscellanceous Menu<br />

Posted: Wed Feb 03, 2010 9:21 am
by Mads Rasmussen
I'm trying to create a user defined tag, that will change the menu in the left column - in the right column resides the main menu.
To load the correct left side menu is doable  this way.

But I'm lazy so I tried to more than one value - if ($thispage == "david_snyder | book-by-david-evans")
The code should allow the "|" sign.


global $gCms;
$thispage ="" ;
$thispage = $gCms->variables['page_name'];
if ($thispage == "david_snyder")  echo "  Miscellanceous Menu




elseif  ($thispage == "book-by-david-evans")  echo " Miscellanceous Menu
";

else echo "";

I tried to create a global_content, like:
global $gCms;
$thispage ="" ;
$thispage = $gCms->variables['page_name'];
if ($thispage == "david_snyder")  echo " {global_content name='allebilleder'} ....



elseif  ($thispage == "book-by-david-evans")  echo " Miscellanceous Menu
";

else echo "";

but that wont work.


Anybody with a great idea?

:-)

Mads Rasmussen

Re: if ($thispage == "david_snyder") echo " <em>Miscellanceous Menu<br />

Posted: Wed Feb 03, 2010 10:25 am
by fredp
Hi,

I think a look at the wiki examples should get you started:   
    http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Extensions/User_Defined_Tags#Long_Version

Hope this helps,
Fred P.

Re: if ($thispage == "david_snyder") echo " <em>Miscellanceous Menu<br />

Posted: Thu Feb 04, 2010 7:36 am
by Mads Rasmussen
I did, Fred P.
And I didn't get any the wiser.

I assume that:

Code: Select all

Passing the page content as a parameter
You can access the page content in a user defined tag by passing it as a parameter:
In your template:
  {content assign=pagecontent}
  {table_of_contents thepagecontent="$pagecontent"}
In your user defined tag named "table_of_contents":
  echo $params['thepagecontent']; // Display page content.
I use this so I can parse to the page content to automatically create a table of contents.
Is a way to go, if modified, but .... ?


I changed:

Code: Select all

if ($thispage == "david_snyder || book-by-david-evans")  echo "  <em>Miscellanceous Menu<br />....
So there are now two "||" which should interpet as "if the first parmeter is meet then ignore the rest".

The editor accept this as valid code, but it doesn't work in preview.

I could of course use:

Code: Select all

global $gCms;
$thispage ="" ;
$thispage = $gCms->variables['page_name'];
if ($thispage == "david_snyder")  echo "  <em>Miscellanceous Menu<br />
   <br />
  </em>
  <ul>
   <li><a href=\"../misc/david_snyder.html\" target=\"_top\">David Snyder</a></li>
   <li><a href=\"../misc/jonathan.html\" target=\"_top\">The Great American Bicycle Wheeze</a></li>
   <li><a href=\"../misc/garageport.html\" target=\"_top\">Garage Port</a></li>
   <li><a href=\"../misc/owners.html\" target=\"_top\">Owners List</a>
   </li>
  </ul>";


elseif  ($thispage == "book-by-david-evans")  echo "<em>Miscellanceous Menu<br />
   <br />
  </em>
  <ul>
   <li><a href=\"../misc/david_snyder.html\" target=\"_top\">David Snyder</a></li>
   <li><a href=\"../misc/jonathan.html\" target=\"_top\">The Great American Bicycle Wheeze</a></li>
   <li><a href=\"../misc/garageport.html\" target=\"_top\">Garage Port</a></li>
   <li><a href=\"../misc/owners.html\" target=\"_top\">Owners List</a>
   </li>
  </ul>";";

else echo "";
but that seems a little bit stupid from a maintainer point of view.
Striving on.
Seems to me that this post is in the catagory?
???

:-)

Mads Rasmussen

Re: if ($thispage == "david_snyder") echo " <em>Miscellanceous Menu<br />

Posted: Fri Feb 05, 2010 12:25 am
by fredp
Mads Rasmussen wrote: I did, Fred P.
And I didn't get any the wiser
....
Hi,

Well, at least it appears you learned that user defined tags are not global content blocks.  That's something. :)
I changed:

Code: Select all

if ($thispage == "david_snyder || book-by-david-evans")  echo "  <em>Miscellanceous Menu<br />....
So there are now two "||" which should interpet as "if the first parmeter is meet then ignore the rest".

The editor accept this as valid code, but it doesn't work in preview.
Hmmm.  Unless, I'm misapprehending your meaning, this isn't correct use of the PHP logical OR operator.
Use logical OR operators to join two conditional expressions.
E.g.:
  if ($thispage == "david_snyder" || $thispage == "book-by-david-evans")...

Code: Select all

global $gCms;
$thispage ="" ;
$thispage = $gCms->variables['page_name'];
if ($thispage == "david_snyder")  echo "  <em>Miscellanceous Menu<br />
   <br />
  </em>
  <ul>
   <li><a href="../misc/david_snyder.html" target="_top">David Snyder</a></li>
   <li><a href="../misc/jonathan.html" target="_top">The Great American Bicycle Wheeze</a></li>
   <li><a href="../misc/garageport.html" target="_top">Garage Port</a></li>
   <li><a href="../misc/owners.html" target="_top">Owners List</a>
...
but that seems a little bit stupid from a maintainer point of view.
...
Indeed! Hard-coding menus into UDTs isn't scalable and is,  in my experience, typically unnecessary.  If you put your content into CMSMS pages, then CMSMS knows your page hierarchy. That means you can use the menu manager (module) to generate all kinds of menus (e.g., horizontal menus, vertical menus, footer menus, etc.) using menu templates and your page hierarchy, stored in the database. Have you looked into using the menu manager?

If not, you might create a test installation of CMSMS and include the optional content and templates. There are multiple examples of menu manager generated menus in there. You can modify a template or make your own to get almost any result you desire.  

The wiki docs have menu manager examples and tutorials, as well:
http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Layout/Menu_Manager#About_the_Menu_Manager

Also search the forums for questions about using the menu manager.  For example:
http://forum.cmsmadesimple.org/index.php/topic,12608.msg62524.html#msg62524

Hope this helps,
Fred P.

EDIT: typo fixed