Make Tag Banner also appear on tagged topic pages

Hello Everyone

I want to know if it’s possible to have form in each tag where at the top of the topic I have the needed details of a client let’s say as tag.

This form could be added in more than one topic and shows the clients details let’s say

without having to create a category since we create categories on another criteria

or any other solutions which will help me to automatically show a client details in more than one topic and category?

I don’t think there’s an existing functionality for this. You’d likely have to use a plugin.

However, I could be mistaken. Could you elaborate further on this? Thanks.

which plugin could help me build this workflow?

Hi there, could you elaborate further on your original question? I might be misunderstanding it.

I think you might have to do something custom, but it’s hard to say for sure without more details.

Is what you’re looking for a form in the tooic post, and adds tags to the topic based on the form’s content? Because then you might be able to get away with a Theme Component instead.

If I’m reading your question correctly, it sounds like you use a tag for each client, and you want an extended client description to show up when viewing any topic having that tag.

It’s not a form really, but the Tag Banners component, as seen here on Meta, might get you halfway there:

With this component installed, you can add a text description for each tag that will appear in a banner shown when the tag itself is selected. The text field takes HTML and can be styled with custom CSS so you could do quite a bit with it, but here’s a very plain example where I’m editing a tag:

The challenge would be to alter this component so that it shows up not only on the tag page, but on each topic using that tag. I don’t know how much work that might be, but a more experienced coder (like Nate…) might have some idea.

2 לייקים

Thanks @toddz that helped a lot that’s what I need

well "@NateDhaliwal the tag banner will help me a lot but now my question is:

How to make it appear in the topic itself where when I add the tag the details appear on the top of the topic

:+1: Ok, since I understood your question I’ll edit the title of this topic so maybe some more people will take a look.

I imagine it would require forking the component to create a new version, figuring out what triggers the banner to appear on the tag page, and changing that so it’s also triggered when tagged topics are viewed.

You could get lucky and someone will think that sounds like fun – otherwise you might need to figure out a project budget and post a request in the Marketplace.

2 לייקים

I’m seeing if this is possible, experimenting with this on a fork. No promises, though!

@Eman_Ahmed I have added this in this fork:

It takes the 1st topic tag and displays it. Controlled by the setting show on topics. If there are no tags, the banner is hidden.

2 לייקים

Very cool of you to take this on, Nate. I don’t have the need for it myself, but I was excited to try it out. It works great!

I do see a gotcha, though, when there are multiple tags on a topic. (And it’s hard to imagine managing things with only one tag per topic.)

Tags are either sorted alphabetically or by popularity…

image

…so the author has no direct control over which tag shows first.

I thought using a non-alpha character to start the client tags (~ClientName) might always pop it to the head of the list. This works on the /tags page – but not on a topic, where the tag list just ignores the ~ character. :face_with_diagonal_mouth:

In a topic from last year, it appears that certain non-alpha characters could be inserted invisibly to force sorting: Invisible way to force display order of tags? but it seems this doesn’t work now. When I create a tag today with an apostrophe or comma it’s either rejected or silently stripped out. (Not sure why ~ is accepted.)

The tag sort setting shown above affects both the /tags page and the tag list on topics – but I guess they must use a different alpha algorithm?

Hmm… I suppose it really depends what OP wishes to do. If there’s 1 tag → 1 topic → 1 user, then this would work. Otherwise, there’ll have to be more info :person_shrugging:.

לייק 1

Thank you for your contribution!

I would like to know whether this could possibly be added to the official feature update list.

I feel that I also have scenarios where this would be very suitable to use.

Hmm… I’m not sure if this is completely aligned with the core concept of a ‘tag banner’, since it was meant to display tag info on the tag’s page, but this displays the tag info in topics with the tag :person_shrugging:.

On a separate note, there have been some updates the main component so I’ll need to try and update the fork as well, but note that the fork is just meant to be a proof-of-concept.

2 לייקים

Yeah, I don’t know if it would be widely useful enough to add the features to the original plugin. A separate version or an add-on called “Tagged Topic Banner” might be more appropriate.

But I think the utility is pretty limited unless there’s also some way for the author to specify which tag will be primary. The only things I can think of are…

1.) A hack like making the alpha-sort treat a character like ~ as top-of-list.

AskBot suggested an approach for a plugin monkey-patch
# plugin.rb
after_initialize do
  module ::CustomTagSort
    def custom_tag_sort(tags)
      tags.sort_by do |tag|
        # Puts ~-prefixed tags first, then sorts A-Z
        [tag.name.start_with?("~") ? 0 : 1, tag.name.downcase]
      end
    end
  end

  # Patch into the serializer/method that computes visible_tags or similar
  require_dependency 'topic_tags_mixin'
  TopicTagsMixin.prepend(Module.new do
    private

    def all_tags
      return @tags if defined?(@tags)
      tags = topic.visible_tags(scope)
      if SiteSetting.tags_sort_alphabetically
        tags = ::CustomTagSort.custom_tag_sort(tags)
      else
        topic_count_column = Tag.topic_count_column(scope)
        tags = tags.sort_by { |tag| tag.public_send(topic_count_column) }.reverse
      end
      @tags = tags
    end
  end)
end

2.) Even better: ordering tags per a specified order of tag groups.

Searching around turns up a number of topics requesting more control over tag order, as it often matters for various reasons (genus → species, make → model, etc.) – but responses suggest it would be a fair bit of work.

לייק 1