Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
What is the best way to add css classes to the link on a rendered entity ?
I want to add the drupal css class "button" so that it is rendered like an HTML button.
By the way this could be a nice feature to add a checkbox "Make it a button instead of a link" don't you think ?
I know that's what the Button Field module already does, but it actually did not work for me so Rules link saved my day.
Comments
Comment #1
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedFor now I have added the "button" css class directly in the module on line 197 of rules_link.module
'#attributes' => array('class' => array('rules-link button'), 'rel' => 'nofollow'),
but I would like to know how I should do it in my template.tpl.php file or if there is another and better way.
Comment #2
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedI actually also want to add a description below the button... so that makes me wonder, is the link a Drupal Field that I could actually theme using field--field-name.tpl.php ?
Comment #3
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedOk for now I have hardcoded my description inside the "#suffix" parameter on line 199. This is so wrong + prevents me from using more than one Rules link on the whole website.
Really need some help on how I'm supposed to do that the right way. Thanks
Comment #4
Adon Irani CreditAttribution: Adon Irani commentedI've got the same use case here.
(Thanks Nicolas for the helpful info above).
Hoping to see this supported in a future release.
Kind regards,
Adon
Comment #5
Ismail Cherri CreditAttribution: Ismail Cherri commentedHi,
I've stumbled upon the same problem and here's how I solved it without hacking the module code:
Insert this in your theme template.php function then clear your cache.
Hope this helps someone out there :)
Comment #6
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedAwesome thanks!
This time I needed a way to change the text with some HTML, perfect place to do it!
Comment #7
bazzmann CreditAttribution: bazzmann at Bazzmann Agency commentedHi there, to us this function break the rules link functionality and it not pass the arguments correctly, displaying the json values instead.
Someone has tested it, without problems?
Thanks in advance,
M.
Comment #8
bazzmann CreditAttribution: bazzmann at Bazzmann Agency commentedSOLVED: we solved the issue including the generated classes in the array to let ajax do the magic.
Thanks. :)
M.
Comment #9
apmsooner CreditAttribution: apmsooner commentedAnother option is overriding the included tpl.php file accordingly. Nevertheless, this issue sounds resolved.
Comment #10
maxplus CreditAttribution: maxplus commentedHi,
I have tried #5 but I'm getting this error
I used the advise of #9 (I have put rules-lin.tpl.php in my theme folder and changed it a little bit) but then all rules links are themed in the same way.
=> It would be cool if we could create tpl files for specific rules links, something like rules-link--machine-name.tpl.php
Comment #11
apmsooner CreditAttribution: apmsooner commented@maxplus,
I agree it would be nice to have more specific templates and while I tried myself to add a template suggestion by rules link name, my template never seems to get picked up in my theme. If i copy the basic rules-link.tpl.php file to my theme... it loads fine. Maybe someone else can comment on why this doesn't work: