numero2 / contao-tags

Adds the possibility to assign tags to individual elements.
GNU Lesser General Public License v3.0
1 stars 3 forks source link

Problem when list, filtered-list and reader have the same alias #11

Closed denniserdmann closed 1 month ago

denniserdmann commented 2 months ago

Moin!

I have 2 pages

and would like to use the News List Modul for both showing the unfiltered list and the filtered tags list to get an url like this: notizen/tag/tag1 but get an error 404 instead. I also tried contao route priority and a third page News Tags with the same alias but thats probably not allowed as i can not save the alias.

Is such scenario possible?

bennyborn commented 2 months ago

If I understand your setup correctly the desired URL structure is unfortunately not possible because Contao can't differentiate if /tag is a tag or the alias of an actual news article. For this reason we added the Use GET-Parameter in the News Tag Cloud module. This should do the trick.

denniserdmann commented 2 months ago

ok, that's what i already thought.

Is there an option to use the Get-Parameter for <?= $tag; ?> (for example in a news_latest template), too?

bennyborn commented 2 months ago

There is no way to configure the behaviour directly but there is some template magic that can help. Assuming you're in a news_list or news_full:

<?php if( $this->tags ): ?>
<div class="tags">
    <ul>
        <?php foreach( $this->tags as $i => $tag ): ?>
        <li>
            <a href="<?= \numero2\TagsBundle\Util\TagUtil::generateUrlWithTags($objPage,[$this->tagsRaw[$i]['tag']],true) ?>">
                <?= $this->tagsRaw[$i]['tag'] ?>
            </a>
        </li>
        <?php endforeach; ?>
    </ul>
</div>
<?php endif; ?>

Note: You may need to replace $objPage with the PageModel of the desired page.