adding CSS class to a Smartytag in CMSmadesimple

141 Views Asked by At

Hi I recently started to re-style a page which uses CMSmadesimple. I have no experience in using CMSms and Smartytags.

but there are some smartytags on the page which need styling.

for example this tag {$entry->morelink}. I need to be able to add this .link CSS class to it.

I have tried everything that I have thought of but nothing seems to work. I have also googled around with out a luck.

I hope there is someone out there that have the experience and knows how to add .class to Smarty tag.

2

There are 2 best solutions below

0
On

This question was asked many times in CMS Made Simple community forums.

Try using Smarty replace variable modifier, for example:

{$entry->morelink|replace:'class="':'class="link '}

In case there is no class attribute on given string, you could stick to replacing id or even closing >.

{$entry->morelink|replace:'id=':'class="link" id='}

It's messy solution but will work. It's better to change initial object.

0
On

There are other approaches to explore. One is using a Smarty tag that doesn't generate the HTML and only provides the value. For example, depending upon the content module, there may be a tag like, "{$entry->moreurl}" which will only provide the URL and not a tag.

Then, you can build your own HTML:

<a href="{$entry->moreurl}" title="{$entry->name}" class="link">View More</a>

You will need to find out what that module supports by adding this to the template and viewing the available params: {$entry|print_r}

If your only option is a tag that also generates HTML, then you can also wrap the Smarty tag inside of a div or span element and assign a class name or id to that.

For example,

<span class="link">{$entry->morelink}</span>

Then your CSS can be written like this:

.link a { color: red; }