Calling the $site_name variable from a module in Drupal 7
Asked Answered
K

3

6

I'm creating a custom module that has uses the form API and sends an email on submission- however, I want to make the 'from' email name to be the site name (eg, <My Drupal Site> [email protected]). In phptemplate you can use $site_name, but that doesn't work from a module it seems. I've tried calling &$variables or &$variable or &$vars in the function argument and DSMed it but still nothing. Any ideas?

Many thanks! Matt

Kocher answered 3/11, 2011 at 10:58 Comment(0)
T
19

You can use:

variable_get('site_name');

anywhere in a module or template file :)

Thorianite answered 3/11, 2011 at 11:3 Comment(1)
Oh my days, that's so obvious that I don't know how it didn't enter my mind! Thanks Clive :)Kocher
P
0

I'd suggest the approach used in core:

variable_get('site_name', 'Drupal');

It's good practice to include the default value in variable_get().

Parbuckle answered 10/6, 2013 at 10:51 Comment(2)
Just curious but are these safe to just echo in the templates or should they be sanitized using check_plain or similar?Reductive
You should sanitize the output with check_plain() just in case your site name is something like "Guns & Roses".Parbuckle
R
0

Done...I dug through the set and get code and none of it ever is sanitized...sanitizing serialized objects would probably break stuff so it makes sense

Reductive answered 26/2, 2014 at 14:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.