Joomla load script in a specific page

前端 未结 1 664
温柔的废话
温柔的废话 2021-01-25 18:02

I\'m creating a website in Joomla and wondering if there is a way to load a specific script in a specific page using php....

e.g. i want to load a :

相关标签:
1条回答
  • 2021-01-25 18:17

    Are you trying to do this in a content item or a component? If you're trying to do it in a component, this is the way to add a JavaScript file to the head portion for only that page:

    $document =& JFactory::getDocument();
    $document->addScript(JURI::base() . 'path/to/sample.js');
    

    If you're trying to do this in a content item, you'll most likely need to find or build a content plugin to scan for a token that tells Joomla to run code like above. I did this on one of the sites I built a while back. I had it set so that a plugin would search for tags like {js sample.js} in content items, extract the file name, add the script to the document, then search and replace the tag out of the article.

    0 讨论(0)
提交回复
热议问题