[SOLVED] if statement based on cgsimplesmarty

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
turpentyne
Forum Members
Forum Members
Posts: 34
Joined: Tue Oct 08, 2013 8:29 pm

[SOLVED] if statement based on cgsimplesmarty

Post by turpentyne »

Calguy gave me a good tip on manipulating content in the template - only problem is, this is the deepest I've had to go in coding for CMSMS, so I'm in new territory.

I'm trying to understand syntax for the cgsimplesmarty plugin, what I want is for a block to appear if the user is in a specific page, or any of its children. I've gotten halfway there, I think, but I'm not sure I understand the aliases and syntax correctly enough to bring it on home... (and I think I stumbled on a glitch between getting title or alias)

Here's what I've got so far:

Code: Select all


{$cgsimple->get_page_title('Starting out',$assign)} <br/>
           {$assign}
// not fulling understanding how to set the variable and then use it
            {$cgsimple->get_page_title($cgsimple->get_parent_alias(), 'maintitle')} 
           <br/>
               {$maintitle2} 
               here? {$the_current_page} <br/>
               {if $maintitle == "Starting out"}
                 ..  {content block = "Sidebar"} ..
                  // this works great for the subpages, but not the parent.
               {/if}

Regarding the glitch (and reason I'm using page titles: when I tried to do get_page_alias, my page wouldn't save for unknown reasons. I don't know if it has something to do with aceEditor that I just installed, or not.
Last edited by turpentyne on Wed Dec 04, 2013 11:07 pm, edited 1 time in total.
turpentyne
Forum Members
Forum Members
Posts: 34
Joined: Tue Oct 08, 2013 8:29 pm

Re: if statement based on cgsimplesmarty

Post by turpentyne »

Ok... made a little progress, by changing the first two lines - cleared out 'starting out' (and fixing variable name, now that I understand a little better):

Code: Select all

{$cgsimple->get_page_title('','parentvariable')} <br/>
{$parentvariable} // echoed for testing
So now, I just need to figure out how to add in my "or" statement to get this wrapped up.
turpentyne
Forum Members
Forum Members
Posts: 34
Joined: Tue Oct 08, 2013 8:29 pm

Re: if statement based on cgsimplesmarty

Post by turpentyne »

Waiiiiit... could it be this simple? I think I got it fixed. If anybody has any thoughts on whether this is fine, or there's a better way, or issues I need to be aware of, let me know. But here's what I ended up with in my template to hide/show a second content block, if they're in a specific content page and any of its subpages.

Code: Select all

{$cgsimple->get_page_title('','ifparent')}        {$cgsimple->get_page_title($cgsimple->get_parent_alias(), 'maintitle')} 
{if ($maintitle == "Starting out") or ($parenttitle == "Starting out")}
       Sidebar<br/>
      {content block = "Sidebar"} 
{/if}            
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: if statement based on cgsimplesmarty

Post by calguy1000 »

given a page structure like this:

1. Page A (alias = "page-a")
2. Page B (alias = "page-b")
2.1 Page B-1 (alias = "page-b-1");
2.1.1 Page B-1-1 (alias = "page-b-1-1")
2.1.2 Page B-1-2 (alias = "page-b-1-2")
2.2 Page B-2 (alias = "page-b-2")
3. Page C (alias = "page-c")

And you have a global content block called 'mygcb' that you want displayed on "page-b" and everything below it.

I'd use syntax like this:

Code: Select all

{cgsimple::get_root_alias('','root_alias')}
{if $root_alias == 'page-b' or $page_alias == 'page-b'}
  {global_content name="mygcb"}
{/if}
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.
Post Reply

Return to “Modules/Add-Ons”