Blogger: Implementing a simple IF with an OR in the condition - if-statement

In my blogger template I have the following code:
<b:if cond='data:blog.pageType == "index"'>
<!-- A lot of lines of code -->
</b:if>
<b:if cond='data:blog.pageType == "archive"'>
<!-- The same lines of code -->
</b:if>
It is possible to merge both 'if's in a unique expresión?. Something like using a simple logical OR?. I've tried the following with no result:
<b:if cond='data:blog.pageType == "index" ||
data:blog.pageType == "index"'>
<b:if cond='data:blog.pageType == "index" ||
data:blog.pageType == "index"'>
<b:if cond='data:blog.pageType == "index" OR
data:blog.pageType == "index"'>
<b:if cond='data:blog.pageType == "index" || "index"'>
<b:if cond='data:blog.pageType == "index" || "index"'>
Note: | is the HTML expression for '|'.
I google it with no result, and I also reviewed blogger b:if statement, but I found no answer to this simple question.
----- edited -----
The desired result is having a code like:
<b:if cond='data:blog.pageType == "index"' ||
cond='data:blog.pageType == "archive"'>
<!-- A lot of lines of code -->
</b:if>
In this way, I don't repeat the block 'lot of lines of code', resulting a more maintainable code, and simplier.
Anyway, knowing how to do a simple OR is a good thing to furure cases.

To simulate an OR operator in a blogger template, just use the IN operator.
In your case:
<b:if cond='data:blog.pageType in {"index","archive"}'>
<!-- This block is run only when the pageType is index or archive-->
</b:if>

The only way I found to accomplish this is transforming the OR to nested, negated ANDs.
In this case, 'data:blog.pageType' has only 4 valid values: item, static, index and archive. So, the following code do the trick:
<b:if cond='data:blog.pageType != "item"'>
<b:if cond='data:blog.pageType != "static"'>
<!-- This block is run only when the pageType is archive or index -->
<!-- A lot of lines of code -->
</b:if>
</b:if>
Edit: This works fine, but maybe you'll want to try the accepted answer given by Marcos.

Related

How can I remove inner text between all <script>..</script/> by a regular expression?

I am trying to use regular expressions, to remove all the content between two strings ...
Suppose this is my content:
<h2>Misrepresentation of the Facts</h2>
</script>
<!-- Articles - Leaderboard 728x90 -->
</iframe></ins></ins></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<h2>Who Can Commit the Crime</h2>
I want to remove all content between </script>
<!-- Articles - Leaderboard 728x90 -->
</iframe></ins></ins></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Any help would be most appreciated.
<\/script>(?:[^<]*(?!.)+<\/script>
<\/script>(?:[^<]*(?!.)+<\/script>
I'm just guessing that these expressions being replaced by an empty string might work:
<\/script>[\s\S]*?<\/script>
<\/script>[\d\D]*?<\/script>
<\/script>[\w\W]*?<\/script>
Please see the demo here.
Escaping is just for demoing, and can be removed.

If-else tag: Which of the following is true?

Normally, the title html in Blogger will appear like this:
<title><data:blog.pageTitle/></title>
If one prefers post title before blog title, you get two types of conflicting codes after google search:
First type:
<b:if cond='data:blog.pageType == "item"'>
<title>
<data:blog.pageName/></title>
<b:else/>
<title>
<data:blog.title/></title>
</title>
</b:if>
Second type:
<b:if cond='data:blog.pageType == "index"'>
<title>
<data:blog.title/></title>
<b:else/>
<title>
<data:blog.pageName/></title>
</b:if>
Which one is true?
What about the new tag <title><data:view.title.escaped/></title>
Otherwise, both of your code is true but the second code is preferred if you want to show post title instead of blog title on both item and static page types (static page like "About").
If you use first type title of item type return article title and for (static, archive, index, search, label) return the blog name.
If you use second type, the title index type (label, search and homepage) use your blog name and for (item, archive, static_page) use article title.
data:blog.pageName avaiable for item, static and archive, for item and static return article title and for archive page return date.

rails: multiple OR statements in current_page?

Why does this code set li class active for only the spree.account_url and ignores the rest even though when only one of the others are valid?
<li class='<%= "active" if current_page?(spree.account_url || edit_user_newsletter_path || orders_path || nilecard_path) %>'>
this doesn't work the way you think it does.
spree.account_url || edit_user_newsletter_path
edit_user_newsletter_path will only be returned if spree.account_url is nil. It's not nil, so spree.account_url is always returned in preference for anything else.
Better would be...
<li class='<%= "active" if [spree.account_url, edit_user_newsletter_path, orders_path, nilecard_path].map{|p| current_page?(p)}.any? %>'>

Blogger template - Inserting code with a specific URL

Blogger template - Inserting code with a specific URL.
I want to put specific meta-titles in a blogger blog. The meta-descriptions I put in the "description search" but the titles I want to manually put. I want it to be a different name than the title of the post.
I followed the instructions here to make the "if/else" conditions: https://support.google.com/blogger/answer/46995?hl=es
I got a code something like this:
<b:if cond='data:blog.pageType == "index"'>
**<title>Motivation</title>**
<b:elseif cond='data:blog.url == "http://www.xxxx1.com"'>
<title>Motivation2</title>
**<b:elseif cond='data:blog.url == "http://www.xxxx2.com"'>**
<title>Motivation3</title>
<b:else/>
<title>~~~~<data:blog.pageName/>~~ <data:blog.title/></title>
</b:if>
But this condition is not working
<b:elseif cond='data:blog.url == "http://www.xxxx1.com"'>
I tested with something like this:
<b:if cond='data:blog.url == "http://www.xxxx1.com"'>
<title>testing32</title>
</b:if>
and is not working either.
To prove that the data:blog.url is working I put a code like:
<b:if cond='data:blog.pageType == "index"'>
**<title><data:blog.url/></title>**
</b:if>
And it shows my URL perfectly....
The only way I found to make it work is by filter by the name of the post.
<b:else cond='data:blog.**pageName** == "motivation"'>
yes, is tedious but if the title has " ' " or " " " or extrange characters blogger not get the code right.
Each entry of your blog have an ID number. You have to use it in order to do a correct filter per post.
Then you can use basic conditional structures like this:
<b:if cond='data:blog.postId == "1234567890"'>
<title>Your custom title for post with ID 1234567890</title>
<b:else/>
<b:if cond='data:blog.postId == "0987654321"'>
<title>Your custom title for post with ID 0987654321</title>
</b:if>
<b:else/>
<!--Default title-->
<title><data:blog.pageTitle/></title>
</b:if>
You can get the postid editing each post and looking at the URL in the Blogger editor, or checking the source code of your post entry searching for "postid".
It's up to you but I would strongly suggest you to do those changes directly editing your posts and modifying manually the corresponding title tag.

Prestashop, Smarty template renders too many buttons

I've got this code in my prestashop template, there is no loop, only conditional, and I get 5 back buttons (elseif section, first li tag), why is it happen?
{if $node.children|#count > 0 && ($smarty.get.controller!='product' && $smarty.get.controller!='category')}
<li class = "li-parent">
<asset class="menu-arrow-left"></asset>
<p><span>{$node.name|escape:'htmlall':'UTF-8'}</span></p>
{elseif $node.children|#count > 0 && ($smarty.get.controller=='product' || $smarty.get.controller=='category')}
<li class="li-back"><asset class="menu-arrow-right"></asset><p class="class="border-bottom-grandiet-small"><span>Back</span></p></li>
<li class = "li-parent">
<p><span>{$node.children[0].name|escape:'htmlall':'UTF-8'}</span></p>
{/if}
I don't see anything in this code that could cause displaying 5 back buttons. I suspect this code is included in some kind of loop and that's why it's displayed 5 times.
You should change the whole above code with:
testonly
and then look at page or page source and check how many testonly texts will appear.
It's also possible if you really use loop that you should use some extra condition. For example instead of:
<li class="li-back"><asset class="menu-arrow-right"></asset><p class="class="border-bottom-grandiet-small"><span>Back</span></p></li>
you should use
{if $node.children|#iteration eq 1}
<li class="li-back"><asset class="menu-arrow-right"></asset><p class="class="border-bottom-grandiet-small"><span>Back</span></p></li>
{/if}
and probably the rest should be more similar to the first condition so instead of:
<li class = "li-parent">
<p><span>{$node.children[0].name|escape:'htmlall':'UTF-8'}</span></p>
you should use:
<li class = "li-parent">
<p><span>{$node.name|escape:'htmlall':'UTF-8'}</span></p>
but it's really hard to say if we don't know what's the data structure and what exactly you want to achieve. If it still doesn't work you should provide more details to your question, explain what you want to achieve, what data you have in your variables and so on.