Page 1 of 1

Format menu items based on conditions

Posted: Wed Oct 11, 2017 4:38 am
by nielsf
Hi,
I maintain a beta site (kind of a staging site) and the "real" site. For users of the beta site, it could be useful to know that the page they are reading only exists on the beta site (so they don't get nervous).
I'm already using conditions to keep the pages from being published to the official site. I thought it would be nice to add a color to the menu item as well.
Is that even possible? As far as I can see, information about conditions in the TOC is not transferred to the html, but only used for selection of pages by the target.
:idea: Ideas are welcome!

Re: Format menu items based on conditions

Posted: Wed Oct 11, 2017 8:51 am
by bianca_writer
Can you include screen shots of the site to show what you want to change? Extra context is helpful. :)

Re: Format menu items based on conditions

Posted: Thu Oct 12, 2017 3:42 am
by nielsf
Sure thing - a picture is worth 1000 words, and all that:
MenuConditionalFormat.png
The menu item in the red box should have a different color than the other menu items, to set it apart.
(Of course the menu item "Internal pages" would be a candidate as well, but you get the idea.)
-Niels

Re: Format menu items based on conditions

Posted: Thu Oct 12, 2017 5:25 am
by NorthEast
You can't do this using conditions (as they're not present in the output), but you can set a style on a menu item, and get this to display in the top nav skin / menu proxy.
See:
* This post: viewtopic.php?f=6&t=29402&p=128508#p128508
* This article: https://www.linkedin.com/pulse/how-i-co ... tte-gagne/

Re: Format menu items based on conditions

Posted: Thu Oct 12, 2017 7:10 am
by nielsf
Thanks, Dave Lee, and also Jbleasdale who suggested going this route in a private IM.
I will look into this. I will need some time to concentrate on it, because I can't see how the styles named in the skin and defined in the css get selectable in the toc entry properties. Preliminary experiments gave me nothing.
I will let you all know how I fare... 8)

Re: Format menu items based on conditions

Posted: Fri Oct 13, 2017 12:05 am
by NorthEast
nielsf wrote:Thanks, Dave Lee, and also Jbleasdale who suggested going this route in a private IM.
I will look into this. I will need some time to concentrate on it, because I can't see how the styles named in the skin and defined in the css get selectable in the toc entry properties. Preliminary experiments gave me nothing.
I will let you all know how I fare... 8)
In the TOC entry properties General tab, select the Style Class that you've created.
Screenshot from the article:
Image

Re: Format menu items based on conditions

Posted: Fri Oct 13, 2017 12:08 am
by nielsf
Thanks, I know - the issue is to get the class to show in there! :)

Re: Format menu items based on conditions

Posted: Fri Oct 13, 2017 12:38 am
by NorthEast
nielsf wrote:Thanks, I know - the issue is to get the class to show in there! :)
Ah, Ok. Step 3 of the article tells you to put it the <Style> block inside the <Styles> block.

But if you're using a brand new skin, then you won't have a <Styles> block, you'll just have an empty <Stylesheet /> line.

So <Style> goes inside <Styles>, and that goes inside <Stylesheet> - so the structure you need in the skin is:

Code: Select all

  <Stylesheet>
		<Styles>
			<Style
				Name="TocEntry">
				<Classes>
					<StyleClass
						Name="MyStyle"
						Custom="true">
						<Properties>
							<Property
							Name="FontSize">1em</Property>
						</Properties>
					</StyleClass>
				</Classes>
			</Style>	
		</Styles>	
  </Stylesheet>	

Re: Format menu items based on conditions

Posted: Fri Oct 13, 2017 2:35 am
by nielsf
OK, now I have time to experiment. I've added the style class in the skin, and the style shows up in the toc entry properties.
I've added the style:

Code: Select all

.TOCbeta > a:after
{
   content: "\f126"; /*code fork */
   font-family: FontAwesome;
   vertical-align: super;
   position: relative;
   left: 5px;
   bottom: 2px;
   color: #ff7045;
   font-size: smaller;
}
However, when I generate the project, the TOCbeta class is not applied to the <li> tag. I had expected the menu to be like this:
menubetastyle.png
and look like this:
menubeta.png
(This pic is from my adding the class manually in the Chrome's Inspect pane).
But there is no indication of my having selected the TOCbeta style class for the menu item anywhere.
Now how can that be. I have a guess: I am running 2017 r2, and the menu generation was changed completely to be generated on-the-fly and not pre-packaged by the target generator. This has screwed with several of my nifty add-ons that required the presence of a menu structure from the get-go.
Are you running 2017 r2?

Re: Format menu items based on conditions

Posted: Fri Oct 13, 2017 3:41 am
by Jbleasdale
Did you apply the styleclass to the TOC item in Flare?

Re: Format menu items based on conditions

Posted: Fri Oct 13, 2017 3:46 am
by nielsf
Sure.
Are you running 2017 r2, Jbleasdale?

Re: Format menu items based on conditions

Posted: Fri Oct 13, 2017 3:57 am
by Jbleasdale
Yes I am.

I remember adding the styles was easy, but I did take a little bit of time to get them to apply properly.

Looking at your code, I think you are trying to add the style to a whole book, whereas mine is an individual topic in the TOC... Thats the only difference I can think of.

Re: Format menu items based on conditions

Posted: Fri Oct 13, 2017 4:03 am
by nielsf
Hi,
Not sure how you arrive at the conclusion that my code should apply to the whole book? Now that would be easy!
No, I only apply it to select TOC entries.
I create the toc style in the skin.
I create the style class in the css.
I apply the style to the TOC entry in its property page.
I generate.
As far as I can tell, that ought to be it.
But I must be doing something wrong since you are also running Flare 2017 r2. So - back to the drawing board... :)

Re: Format menu items based on conditions

Posted: Fri Oct 13, 2017 4:14 am
by nielsf
Sorry - now it seems to work! I generated it again...
OK, it almost works! When the menu item is selected, it loses its new formatting.
Works:
menubetaNotSelected.png
Doesn't work (selected):
menubetaSelected.png
Looking in the code, the TOCbeta class is stripped from the entry when it is selected.
Anyway, my initial question was answered - thanks!

Re: Format menu items based on conditions

Posted: Fri Oct 13, 2017 6:35 am
by Jbleasdale
Glad to hear its working (kind of).

The book I was referring to was the TOC book (a collection of topics). Not the whole project.

The styling issue is likely because there is some CSS that overrides the TOC style when the item is selected. The dev tools should tell you that.

Re: Format menu items based on conditions

Posted: Fri Oct 13, 2017 7:36 am
by NorthEast
I had a look - when you select an item from the TOC in the menu proxy, it will not include the TOC style class for the 'book' topics only (book is any topic with a child topic).
That not only applies to the selected topic, but also all child and parent topics (that are books too) in that part of the menu tree. Sibling books topics are ok.

When I suggested this solution, I thought it worked ok - but seems like it works fine for the top nav menu, but not properly for menu proxies.