How do I add a message to the Categories page?


(Robert Lauriston) #1

I want to add a message to the Categories page telling users how to request a new category.

I tried a header variation on the approach discussed here:

But nothing showed up after I enabled the header and CSS.

I don’t really want the message in the header anyway, I would prefer it to appear after the banner ad and before the Catgories / Latest / Topics table heading.


HTML field just for homepage
(Krischan) #2

I would love to know how to do this as well. Can anyone help?


(Joe Seyfried) #3

Try this:

add a <div id="cat-page-only"> to your “Top” customization which contains your desired content you want to show on the categories page. Then, add these styles:

#cat-page-only {
    display: none;
}
body.categories-list #cat-page-only {
    display: block;
    /* mo' stuff here, make it red, blink, nice and easy */
}

(Robert Lauriston) #4

I created a customization named categories-page-intro containing this on the CSS tab:

#cat-page-only {
    display: none;
}
body.categories-list #cat-page-only {
    display: block;
    /* mo' stuff here, make it red, blink, nice and easy */
}

and this on the Top tab:

<div id="cat-page-only">introductory text for the categories page</div>

The message is appearing above the Categories / Latest / New / Unread nav, rather than between the banner ad and the category list.


(Joe Seyfried) #5

Oh boy - if you want it to go EXACTLY there, you need to do some darker magic. One not-so-pretty solution could be this one: Drop the Top tab and add this to your Header customization section:

<script>
var cat_page_html='<div id="cat-page-only">introductory text for the categories page</div>';
$('body').attr('onload','jQuery(".list-controls").append(cat_page_html)');
</script>

…and leave the CSS part unchanged. Customize the cat_page_html to your liking…

I guess one of the team can give you some advice on how to do that trick without invoking jQuery() - the only alternative that I can think of involves modifying a .hbs template - and I’m note sure which alternative I like less.

Edit: of course, you could call the onload-part only if you’re on the categories page like so (assuming that your home page is the categories page, omit any pathname where you don’t want to display the div):

if ((window.location.pathname == "/") || (window.location.pathname == "/categories")){
...
}

(Mittineague) #6

Please, save yourself from some headaches and if at all possible try using the discovery-list-container-top plugin-outlet instead


(Joe Seyfried) #7

Sure - I meant overriding the hbs from a userscript - is there a way to access the outlets from there? I was under the impression the plugin-outlets are meant for plugins only?


(Mittineague) #8

I don’t know if they could be used in other ways, but they make plugin writing a lot easier.

In this case, plugin.rb would have the usual comments and something like

register_asset "javascripts/discourse/templates/connectors/discovery-list-container-top/show-discovery-list-container-top-location.hbs"

where the file “show-discovery-list-container-top-location.hbs” woud be named something meanngful.

And show-discovery-list-container-top-location.hbs would have something like

{{#if controller.siteSettings.in_discovery_enabled }}
<div id="in-discovery">
<i class="fa fa-plug"></i>
Discovery plugin outlet is here
</div>
{{/if}}

where the mark-up and text would be whatever you want.

* the “if” and div id are optional and in this case allow toggling the feature and a way to use CSS ro style it

The only part I don’t know without looking into it ATM is finding a way to limit its display to other than multiple pages, but I think using CSS display: none; display: block; could easily work.


(cpradio) #9

No, they aren’t.