Running in to some issues with Tumblr's Theme Parser - tumblr

Below part of a tumblr theme I'm working on and you will notice that I use the {block:PostType} syntax to declare the opening tag of each post, which is a <li> element in an Ordered List. This allows me to not only dynamicly set the li's class based on the type of post but cuts down on the number of times I'm calling the ShareThis JS which was really bogging down the page. This creates a new issue though which I believe is a flaw in Tumblr's parser. Each post is an ordered list with one <li> element in it. I know I could solve this by having each post as a <div> but I really like the control and semantics of using a list. Tumblr gurus? Suggestions?
Sample of code:
{block:Posts}
<ol class="posts">
{block:Text}
<li class="post type_text" id="{PostID}">
{block:Title}
<h2>{Title}</h2>
{/block:Title}
{Body}
{/block:Text}
{block:Photo}
<li class="post type_photo" id="{PostID}">
<div class="image">
<img src="{PhotoURL-500}" alt="{PhotoAlt}">
</div>
{block:Caption}
{Caption}
{/block:Caption}
{/block:Photo}
{block:Photoset}
<li class="post type_photoset" id="{PostID}">
{Photoset-500}
{block:Caption}
{Caption}
{/block:Caption}
{/block:Photoset}
{block:Quote}
<li class="post type_quote" id="{PostID}">
<blockquote>
<div class="quote_symbol">“</div>
{Quote}
</blockquote>
{block:Source}
<div class="quote_source">{Source}</div>
{/block:Source}
{/block:Quote}
{block:Link}
<li class="post type_link" id="{PostID}">
<h2>{Name}</h2>
{block:Description}
{Description}
{/block:Description}
{/block:Link}
{block:Chat}
<li class="post type_chat" id="{PostID}">
{block:Title}
<h2>{Title}</h2>
{/block:Title}
<table class="chat_log">
{block:Lines}
<tr class="{Alt} user_{UserNumber}">
<td class="person">{block:Label}{Label}{/block:Label}</td>
<td class="message">{Line}</td>
</tr>
{/block:Lines}
</table>
{/block:Chat}
{block:Video}
<li class="post type_video" id="{PostID}">
{Video-500}
{block:Caption}
{Caption}
{/block:Caption}
{/block:Video}
{block:Audio}
<li class="post type_audio" id="{PostID}">
{AudioPlayerWhite}
{block:Caption}
{Caption}
{/block:Caption}
{block:ExternalAudio}
<p>Download</p>
{/block:ExternalAudio}
{/block:Audio}
<div class="post_footer">
<p class="post_date">Posted on {ShortMonth} {DayOfMonth}, {Year} at {12hour}:{Minutes} {AmPm}</p>
<ul>
<li><a class="comment_link" href="{Permalink}#disqus_thread">Comments</a></li>
<li><script type="text/javascript" src="http://w.sharethis.com/button/sharethis.js#publisher=722e181d-1d8a-4363-9ebe-82d5263aea94&type=website"></script></li>
</ul>
{block:PermalinkPage}
<div id="disqus_thread"></div>
<script type="text/javascript" src="http://disqus.com/forums/kyleetilley/embed.js"></script>
<noscript>View the discussion thread.</noscript>
{/block:PermalinkPage}
</div>
</li>
</ol>
{/block:Posts}

The Posts block is executed once for each post, thus the markup for the container should go outside this block.
Just put the <ol> right before {block:Posts} and the </ol> directly after the {/block:Posts}

Try this, it worked for me when I put it into the Theme Parser. I've modified your code a little bit:
overhauled your syntax to be intended. Please don't take offense, I only did it for clarity's sake!
move the <ol> element outside of the {block:Posts} as everything inside it is rendered once for each type of post.
moved and modified your <li> element so that's no longer specific to the type of post, Tumblr provide a neat little {PostType} variable that will print each post's type (except for photoset; for which it prints "photo", but I've added a little bit more in there to account for that.) This is faster to render and simpler to read.
swapped your {AudioPlayerWhite} to {AudioPlayer}, this is just because Tumblr sometimes gets upset if you define the audio player's colour, and a message is displayed on tumblr.com/new/audio saying "Your theme does not support proper audio players". Probably not connected to the problem but it's a good practice
Working example: stackoverflow-theme-test-1.tumblr.com - ignore how it looks because I didn't apply any styling, but the code is all perfectly valid.
<ol class="posts">
{block:Posts}
<li class="post type_{PostType}{block:Photoset}set{/block:Photoset}" id="{PostID}"> <!--Saves you from having to manually define each type of post-->
{block:Text}
{block:Title}
<h2>{Title}</h2>
{/block:Title}
{Body}
{/block:Text}
{block:Photo}
<div class="image">
<img src="{PhotoURL-500}" alt="{PhotoAlt}">
</div>
{block:Caption}
{Caption}
{/block:Caption}
{/block:Photo}
{block:Photoset}
{Photoset-500}
{block:Caption}
{Caption}
{/block:Caption}
{/block:Photoset}
{block:Quote}
<blockquote>
<div class="quote_symbol">“</div>
{Quote}
</blockquote>
{block:Source}
<div class="quote_source">{Source}</div>
{/block:Source}
{/block:Quote}
{block:Link}
<h2>{Name}</h2>
{block:Description}
{Description}
{/block:Description}
{/block:Link}
{block:Chat}
{block:Title}
<h2>{Title}</h2>
{/block:Title}
<table class="chat_log">
{block:Lines}
<tr class="{Alt} user_{UserNumber}">
<td class="person">{block:Label}{Label}{/block:Label}</td>
<td class="message">{Line}</td>
</tr>
{/block:Lines}
</table>
{/block:Chat}
{block:Video}
{Video-500}
{block:Caption}
{Caption}
{/block:Caption}
{/block:Video}
{block:Audio}
{AudioPlayer} <!--Tumblr don't like you to specify a colour for the {AudioPlayer}, you could do anyway, but in the interests of minimising parsing errors I havent-->
{block:Caption}
{Caption}
{/block:Caption}
{block:ExternalAudio}
<p>Download</p>
{/block:ExternalAudio}
{/block:Audio}
<div class="post_footer">
<p class="post_date">Posted on {ShortMonth} {DayOfMonth}, {Year} at {12hour}:{Minutes} {AmPm}</p>
<ul>
<li><a class="comment_link" href="{Permalink}#disqus_thread">Comments</a></li>
<li><script type="text/javascript" src="http://w.sharethis.com/button/sharethis.js#publisher=722e181d-1d8a-4363-9ebe-82d5263aea94&type=website"></script></li>
</ul>
{block:PermalinkPage}
<div id="disqus_thread"></div>
<script type="text/javascript" src="http://disqus.com/forums/kyleetilley/embed.js"></script>
<noscript>View the discussion thread.</noscript>
{/block:PermalinkPage}
</div>
</li>
{/block:Posts}
</ol>

Related

I'm having problems with applying padding to my navbar (when expanding it)

I want the navbar always to be of a certain height, but when applying certain padding, when expanding the menu the whole navbar expands, and the initial not expanded navbar 'loses' part of its height, and also you see that padding to the sides. It's a bit tricky for me to explain but you'll hopefully see what I mean in this example:
#navbarMain {
background-image: linear-gradient(#6ebebe, #28648c 80%);
padding: 1rem;
}
.navbar-nav {
background-color: white;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<nav id="navbarMain" class="navbar navbar-expand-lg navbar-dark fixed-top shadow">
<a class="navbar-brand" href="/"> <i class="fas fa-book text-light"></i> Navbar Brand</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Toys</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Store</a>
</li>
</ul>
</div>
</nav>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
As you can see, when expanded the gradient is being applied to the whole expanded navbar (brand + li) , and I need that gradient to be applied only an always to the initial 'non expanded navbar' (brand section). Is it a way to keep the 'not expanded navbar’ applied properties sort of independent from the expanded menu?
Thanks in advance.
You may use a media query to solve this problem
check this link may solve your issue

How to hide the name of a page from a list if it has no child sub pages in sightly?

I want to display only those pages in the header which have child pages inside them. Using the following code
<nav class="wsmenu clearfix" data-sly-use.nav="in.gov.odishatourism.core.models.HeaderNavigation">
<ul class="wsmenu-list" >
<li aria-haspopup="true" data-sly-repeat="${nav.root.listChildren}" ><span class="wsmenu-click" ><i class="wsmenu-arrow fa fa-angle-down"></i></span>
<a class="" href="javascript:void(0);" data-sly-test="!${item.hasChild}">${item.title}</a>
<div class="wsmegamenu clearfix ">
<div class="container paddingmenu">
<div class="row">
<div class="menuimgdiv" data-sly-repeat.subcategory="${item.listChildren}">
<h3 class="title" data-sly-test.subcat="${subcategory.title}" >${subcat}</h3>
<ul>
<li data-sly-repeat.page="${subcategory.listChildren}"><a class="" href="${page.path # extension='html'}">${page.title}</a></li>
</ul>
</div>
</div>
</div>
</div>
</li>
<li aria-haspopup="true"> Dept of Tourism</li>
</ul>
<a class="wsdownmenu-animated-arrow"><span></span></a>
<div class="wsdownmenu-text">Navigation</div>
</nav>
gives the following output
But this code -
<nav class="wsmenu clearfix" data-sly-use.nav="in.gov.odishatourism.core.models.HeaderNavigation">
<ul class="wsmenu-list" >
<li aria-haspopup="true" data-sly-repeat="${nav.root.listChildren}" ><span class="wsmenu-click" ><i class="wsmenu-arrow fa fa-angle-down"></i></span>
<a class="" href="javascript:void(0);" data-sly-test="${item.hasChild}">${item.title}</a>
<div class="wsmegamenu clearfix ">
<div class="container paddingmenu">
<div class="row">
<div class="menuimgdiv" data-sly-repeat.subcategory="${item.listChildren}">
<h3 class="title" data-sly-test.subcat="${subcategory.title}" >${subcat}</h3>
<ul>
<li data-sly-repeat.page="${subcategory.listChildren}"><a class="" href="${page.path # extension='html'}">${page.title}</a></li>
</ul>
</div>
</div>
</div>
</div>
</li>
<li aria-haspopup="true"> Dept of Tourism</li>
</ul>
<a class="wsdownmenu-animated-arrow"><span></span></a>
<div class="wsdownmenu-text">Navigation</div>
</nav>
gives the output as shown below
The code
<a class="" href="javascript:void(0);" data-sly-test="${item.hasChild}">${item.title}</a>
is not working properly.
My site structure is as shown below
And the actual desired output is
You cannot use ${item.hasChild} in your test condition as the hasChild() method of the Page API requires you to pass a parameter. AFAIK, HTL doesn't support invocation of parameterized methods.
Since there is no direct API available to check if a page has child pages or not, you may need to do the following to validate if the page has child pages
<a class="" href="javascript:void(0);" data-sly-test="${item.listChildren && item.listChildren.hasNext}">${item.title}</a>
However, I would prefer building the entire navigation tree using Sling models or WCM Use API and not invoking so many methods in the HTL. That would make the code easier to maintain, change and test. YMMV

Typo3 Carousel DCE Optimize Code

I want to optimize my working carousel and I want to use for:each.
Does anyone maybe see my error?
Working Quote Code
New not working Quote Code
<div class="carousel slide" data-ride="carousel" id="quote-carousel">
<!-- Bottom Carousel Indicators -->
<ol class="carousel-indicators">
<f:for each="{field.person}" as="person" iteration=“iterator“>
<li data-target="#quote-carousel" data-slide-to="{iterator.index}" {'class="active"'->f:if(condition:iterator.isFirst)}></li>
</f:for>
</ol>
<!-- Carousel Slides / Quotes -->
<div class="carousel-inner" role="listbox">
<f:for each="{field.person}" as="person" iteration=“iterator“>
<!-- Quote {iterator.index -->
<div class="item {'active'->f:if(condition:iterator.isFirst)}">
<blockquote>
<f:format.html>{person.expert}</f:format.html>
<small>{person.expertName}</small>
</blockquote>
</div>
</f:for>
</div>
<!-- Carousel Buttons Next/Prev -->
<a data-slide="prev" href="#quote-carousel" class="left carousel-control">
<span style="top: 25%;" class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a data-slide="next" href="#quote-carousel" class="right carousel-control">
<span style="top: 25%;" class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>

where should glyphicon code be inserted

Fist of all I am new to css/javascript/bootstrap.
All I want is to place this code:
<i class="fi-guide-dog"></i>
inside my span (or somewhere) so the dog icon shows next to the "Dog" word.
Please find my code below:
{%load static%}
<link rel="stylesheet" type="text/css" href="{% static 'toarnatot/style.css' %}" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle= "collapse" data-target ="#topnavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href={%url 'toarnatot:home'%}><strong>ToarnaTot</strong></a>
</div>
<!-- items -->
<div class="collapse navbar-collapse">
<ul class ="nav navbar-nav">
<li class="">
<a href="{% url 'toarnatot:home'%}">
<span class="glyphicon glyphicon-something" aria-hidden="true">
Dog
</span>
</a>
</li>
</ul>
</div>
</div>
</nav>
Do not put anything inside the span tag , instead create another tag to print the text that you want to display with the glyphicon.
like:
<p>dog</p>
<span class="glyphicon glyphicon-something" aria-hidden="true"></span>

Microdata for sidebars with list of articles

This is The structure of my first page site
<body>
<div class="header"></div>
<div class="left_col">List of last articles/news</div>
<div class="center_cod">List of feature articles/news</div>
<div class="right_col">other thing like ads,and other item list</div>
<div class="footer"></div>
</body>
What do you suggested me to use Microdata in each of element?
<body itemscope itemtype="http://schema.org/WebPage">
<div class="header" itemscope itemtype="http://schema.org/WPHeader"></div>
<div class="left_col" itemscope itemtype="?">List of last articles/news</div>
<div class="center_cod" itemscope itemtype="?">List of feature articles/news</div>
<div class="right_col" itemscope itemtype="?">other thing like ads,and other item list</div>
<div class="footer" itemscope itemtype="http://schema.org/WPFooter"></div>
</body>
Yes I know there is 'itemscope itemtype="http://schema.org/WPSideBar"' for sidebar...But I wana more cutomize it... for example can I use 'blog' or something like this?