0

So I have this php code in my joomla site (joomla's latest article module) and I'd like to add a bootstrap tooltip to the title of my links. Can someone point me in the right direction as to how I add this script to a php page. Thanks in advance. Here's the script i got from w3schools.

<script>
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();   
});
</script>

and my code which i already have.

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_articles_latest
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
defined('_JEXEC') or die;
?>
<div style="float: left;margin-right: 47px;">

<ul class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) :  ?>
<li itemscope itemtype="http://schema.org/Article">
    <a href="<?php echo $item->link; ?>" data-toggle="tooltip" title="<?php echo $item->title; ?>" itemprop="url"><img src="/images /sound.png" />&nbsp;
        <span itemprop="name">
            <?php echo $item->title; ?>
        </span>
    </a>
</li>
<?php endforeach; ?>
</ul></div>
8
  • just put that script block in your header and include the jquery library somewhere else on the page and you should be fine. Commented Sep 3, 2015 at 15:18
  • Hi thanks for comment. The page doesnt load once i put the js script into it the way it is. Just to be sure (since i am very new to php) between the <?php (this is head?) ?> would be the header right? Commented Sep 3, 2015 at 17:51
  • Negative. You need to add that java script into the <head></head> section of your html. Commented Sep 3, 2015 at 21:33
  • is that chunk of code included in another document, or is there more to this document that is not shown? this is not a complete document on its own. Commented Sep 3, 2015 at 23:29
  • like i said im working on a JOOMLA site. This is a php document for the latest articles module from joomla. All i want to do is add tooltips to titles in a list element. If some one can help me impliment js into a php document then maybe i can do the rest. Commented Sep 4, 2015 at 0:02

1 Answer 1

1

Please enter the following code inside below defined('_JEXEC')

JFactory::getDocument()->addScriptDeclaration('
$(document).ready(function(){
$(\'[data-toggle="tooltip"]\').tooltip();   
});

');

It will include the script into header automatically

Sign up to request clarification or add additional context in comments.

1 Comment

fortunately this code didnt cause my homepage not to load but I still the tooltips arent showing. I already have bootstrap and jquery .js on my site (used with other modules and stuff) so dont think its needed on this php document? Unfortunately I can post the url so anyone have any idea why bootstrap tooltip not showing. Thanks for your response Knight Rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.