X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Add emphasis to category heading in smarty (https://forum.x-cart.com/showthread.php?t=56119)

Bellarama 10-21-2010 01:05 AM

Add emphasis to category heading in smarty
 
Hello,

Just looking for some guidance on how to add in some em tags within smarty

In my template is the following code:
Code:

{if $page_title}
    <h1>{$page_title|escape}</h1>
{/if}


What I would like to do, is detect whether the title is more than one word, and if it is wrap the subsquent words in em tags, so I can style them different.

So for example this is what i want to achieve:
HTML Code:

<h1>New <em>Arrivals</em></h1>

I tried to write some code using the same syntax as the rest of the smarty template, like so:
Code:

{if $page_title}
        {$space_location = strpos($page_title," "); }{*finds the location of the first space, if there is one*}
        {if $space_location}{*if there is a space (a second word exists in the subject)*}
                {*take the location between first position and space and add an em tag*}
                {$thisPageTitle = substr($page_title, 0, $space_location) . "<em>" . substr($page_title, $space_location)}
                {*add a closing em tag to end of string*}
                {$thisPageTitle = thisPageTitle . "</em>"}
        {else}
            {$thisPageTitle = $page_title}
        {/if}
        <h1>{$thisPageTitle|escape}</h1>
{/if}


However this actually doesn't work, so I was wondering if it is possible to do what I want and if so how would I do that??


Many Thanks!!!

Christine

cherie 10-21-2010 12:09 PM

Re: Add emphasis to category heading in smarty
 
You can use this method which acts similar to a split:

Code:

{ assign var=pageTitleArray value=" "|explode:$page_title }


All times are GMT -8. The time now is 01:18 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.