Results 1 to 5 of 5

Thread: InsertTag for title of tag page

  1. #1
    New user
    Join Date
    07-08-09.
    Posts
    15

    Default InsertTag for title of tag page

    I want an insert tag so that I can create a title that dynamically updates based on the tag the user is looking at.

    For example:

    I have a news archive with many tags on the posts. When a user clicks on a tag from the tag-cloud or tag-list, and they are taken to a page containing only the items tagged with that tag, I want the title to say "Read articles about {{current-tag}}"

    Is this possible?

  2. #2
    New user
    Join Date
    07-25-09.
    Posts
    29

    Default Re: InsertTag for title of tag page

    Hi Logan

    yes this is possible, however, you'll have to modify the core tags php file. This one should sort out the news tags

    /system/modules/tags/ModuleNewsListTags.php


    Look for (around line-70)
    Code:
    $relatedlist = (strlen($this->Input->get('related'))) ? split(",", $this->Input->get('related')) : array();
    			$alltags = array_merge(array($this->Input->get('tag')), $relatedlist);
    			global $objPage;

    and add this below;
    Code:
    $objPage->title = ucwords(htmlspecialchars(join(', ', $alltags)));
    So you should end up with;
    Code:
    $relatedlist = (strlen($this->Input->get('related'))) ? split(",", $this->Input->get('related')) : array();
    			$alltags = array_merge(array($this->Input->get('tag')), $relatedlist);
    			global $objPage;
    	  $objPage->title = ucwords(htmlspecialchars(join(', ', $alltags)));
    Heres' an example of this working;

    http://www.carocomarketing.com/inter...marketing.html

    Cheers

    Nigel
    Internet Marketing is both measurable and accountable.
    On Twitter Marketing Guy
    On LinkedIn Nigel Copley
    On Facebook Caroco Marketing

  3. #3
    hamelame
    Gast

    Default Re: InsertTag for title of tag page

    where are you using PHP file ? I think there are many ways to use php file !

  4. #4
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: InsertTag for title of tag page

    Hi there,

    1. For the specific case you're describing, you can do this by customizing the mod_newslist template (copy it into /templates/your-theme-folder/).

    Change the headline portion of the the template accordingly:

    Code:
    // If a headline is set in the module
    <?php if ($this->headline): ?>
    
    // If there are tags currently active...
    <?php if ($this->tags_activetags[0]): ?>
    	// Then display this headline, using the first active tag..	
    	<<?php echo $this->hl; ?>>Read Articles About <?php echo $this->tags_activetags[0]; ?></<?php echo $this->hl; ?>>
    // If there are no active tags...
    <?php else: ?>
    	// Then just display the headline set in the module as you normally would...
    	<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
    <?php endif; ?>
    
    <?php endif; ?>
    Active tags are included as a template variable, as you can see above. If your implementation allows multiple tags to be selected, you can modify the above to loop through $this->tags_activetags and display each one (or use implode() or something).


    2. Even if you couldn't do the above, you should never really need to modify the core files -- Contao is designed specifically with this in mind. By doing so, you are risking breaking it whenever you do an update (since you will likely overwrite your changes).

    One of the many ways you can extend it is by using hooks (http://www.contao.org/hooks.html). In your case, you can use the "replaceInsertTag" hook to create your own custom insert tags. The system will pass any insert tags it doesn't recognize to a custom function that you specify.

    For example:

    Code:
    // If this was the tag you used in your template or module...
    {{current-tag}}
    Code:
    <?php
    // This is in a new file: /system/modules/MyInsertTags/MyInsertTags.php
    class MyInsertTags
    {
    	public function ReplaceMyInsertTags($strTag)
    	{
    		// $strTag will be be passed in as the string "current-tag"
    		if ($strTag === 'current-tag')
    		{
    			// You can then do what you want with it... Maybe incorporate the other guy's code, for example...
    		}
    		return $strTag;
    	}
    }
    ?>
    Code:
    <?php
    // And then one more new file: /system/modules/MyInsertTags/config/config.php
    // This tells Contao to run your custom code above when it finds an insert tag that it doesn't recognize.
    $GLOBALS['TL_HOOKS']['replaceInsertTags'][] = array('MyInsertTags', 'ReplaceMyInsertTags');
    ?>
    Brian

  5. #5
    New user
    Join Date
    08-21-12.
    Posts
    1

    Default Re: InsertTag for title of tag page

    Thanks for that, I know there are some themes that you can use, that have that feature as standard, but knowing how to do it manually gives me far more flexibility.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •