4

I need to use some fonts from Typekit on the site I'm working on. Without the help of an extra module would be the best solution.

I have two lines to go in the of page.tpl.php that call scripts.(< script >< /script >)

Should I put them in /themes/mytheme/template.php ? If so how, can you give me an example of what the code should look like?

Can I just put the call for the scripts right in the page.tpl.php file? with drupal_add_js ?

Anything else I should know?

Helpful links would be cool too. I got a bunch from #drupal on IRC today but none pinpointed it enough for me.

Thanks

Drupal 6

1

If you want the typekit code on every page of your site and you don't want a complicated solution just put the code in the page.tpl.php file. They are external scripts I assume so drupal_add_js won't help you in D6.

You can add things to the scripts variable in template_preprocess_page(), but if you are going to do that on every page then you may as well just put it next to where the scripts are printed in page.tpl.php

  • I'm guessing template_preprocess_page() is in template.php, yeah? How is adding the scripts there any different than adding them to page.tpl.php ? – winchendonsprings Jul 5 '11 at 9:21
  • Both are very similar, the effect will be the same. Putting them in the page.tpl.php is perhaps simpler and more obvious. But if you put them in the variable you do have more options for modifying. – Jeremy French Jul 5 '11 at 9:23
  • Have you got a link where I can see what the code should look like in template.php or page.tpl.php ? Not my strong suit so a reference would be perfect. – winchendonsprings Jul 5 '11 at 9:39
  • stackoverflow.com/questions/3668474/… have a look at some of the examples here – Jeremy French Jul 5 '11 at 9:52
0

I personally like the preprocess function, but you can also hardcore the script in the page.tpl.php or html.tpl.php (inside the tags)

Here is some sample code for the preprocess function. This would go inside template.php:

/**
* Implements template_preprocess_html().
*/

function MYTHEME_preprocess_html(&$variables) {
 //Adds typekit js to theme
 drupal_add_js('//use.typekit.net/wje3ojf.js', 'external');
 drupal_add_js('try{Typekit.load();}catch(e){}', 'inline', 'page_bottom');
}

I wrote an article on how to do this if you want to read the whole thing:

http://cheekymonkeymedia.ca/blog/drupal-planet/how-add-typekit-fonts-your-drupal-website

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.