Welcome Guest, Not a member yet? Register   Sign In
Auto_LInk - how to add a class to the resulting link
#1

[eluser]JamesTaylor[/eluser]
When using the Auto_Link function of the URL helper what is the best way to incorporate a class with the link that is created?

I want to be able to style all Auto_Links in a specific manner via css so I would like to include class="AutoLink" into the output code but there doesn't appear to be an option to do so in the parameters it takes?

Anyone else dealt with this issue before?

Thanks

James
#2

[eluser]Georgi Budinov[/eluser]
Straight from the User guide :

Code:
echo anchor('news/local/123', 'title="My News"');

so this get like :

Code:
echo anchor('news/local/123', 'class="autolink"');

Uuups didn't catch what you meant...
#3

[eluser]JamesTaylor[/eluser]
Georgi, i am not using the anchor tag to create links in this instance. I am using the auto_link tag and am wanting to achieve the equivilient to what you have shown.
#4

[eluser]Georgi Budinov[/eluser]
Yes I realized that Sad OK no way as I see the problem!
However you can overwrite the function by creating your own my_url_helper updating the code:

Code:
function auto_link($str, $type = 'both', $popup = FALSE, $customClass = FALSE)
    {
        if ($type != 'email')
        {
            if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches))
            {
                $pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
                $pop .= ($customClass) ? " class=\"".$customClass."\" " : "";

Not tested but something like this will help.




Theme © iAndrew 2016 - Forum software by © MyBB