Readwise: Yellow Highlight Not Displaying Color (Jinja2) - jinja2

I export my highlights from Kindle to Readwise then from Readwise to Obsidian.
In my kindle app, I use all the highlight colors for different purposes (Pink, Blue, Orange Yellow). Readwise treats "Yellow" as the default so it doesn't create a color tag for this tag and I use Yellow for my more important highlights. What I'm trying to do is create a color tag
Here is my default code before changes:
- {{ highlight_text }}{% if highlight_location and highlight_location_url %} ([{{highlight_location}}]({{highlight_location_url}})){% elif highlight_location %} ({{highlight_location}}){% endif %}{% if highlight_tags %} {% for tag in highlight_tags %}#hl-{{tag}} {% endfor %}{% endif %}{% if highlight_note %}
- Note: {{ highlight_note }}{% endif %}
So this is where I am stuck.. The code above works, but #hl-yellow will not display.. Any suggestions on how I can get this to work?
Update:
So I was able to create a work around so all highlights begin with ##hl and the colors are added with if statements by adding -red -blue -orange instead of it being #hl-red, #hl-blue, and #hl-orange.
So now the output is #hl for yellow, #hl-blue for blue, #hl-orange for orange, and #hl-red for pink.
Is there any way I can subtract a certain amount of characters before I add a color? That way the default tag can be #hl-yellow and I can subtract 6 characters and then just replace the 6 characters from yellow with red blue orange. Is this possible?
Updated Code:
- {{ highlight_text }}{% if highlight_location and highlight_location_url %} ([{{highlight_location}}]({{highlight_location_url}})){% elif highlight_location %} ({{highlight_location}}){% endif %} #hl{% if highlight_tags %}{% for tag in highlight_tags %}{% if tag == "pink" %}-red{% elif tag == "orange" %}-orange{% elif tag == "blue" %}-blue{% else %}-yellow{% endif %} {% endfor %}{% endif %}{% if highlight_note %}
- Note: {{ highlight_note }}{% endif %}

If you add ".yellow" to a note in Kindle then that note will be displayed in Readwise with a "yellow" tag.

Related

How to remove empty line in Jinja (exporting from readwise to logseq)

I am trying to export highlights from readwise to logseq with correct page properties.
However for some pages an empty line appears which prevents all properties to appear correctly.
How can I fix this?
This is the current jinja code:
author:: [[{{author}}]]\
full-title:: "{{full_title}}"\
category:: #{{category}}\
if url %}url:: {{url}}{% endif %}\
if document_note %}document_note:: {{document_note}}{% endif %}\
if document_tags %}tags:: {% for tag in document_tags %}#[[{{tag}}]] {% endfor %} {% endif %}
if image_url %}![]({{image_url}}){% endif %}`
ine issue for example: If document note is empty it still creates a line for that property
I managed to fix it:
author:: [[{{author}}]]\
full-title:: "{{full_title}}"\
category:: #{{category}}\
{% if url %}url:: {{url}}{% endif -%}\
{% if document_note %}document_note:: {{document_note}}{% endif -%}
{% if document_tags %}tags:: {% for tag in document_tags %}#[[{{tag}}]] {% endfor %} {% endif %}\
{% if image_url %}![]({{image_url}}){% endif %}
Changes include adding - before the % in the endif

How do I hide a specific tag from a Shopify navigation?

we are trying to hide a specific tag/filter from one of our collection pages' navigations without deleting the tag from the products themselves as we still need this tag for other functionalities.
Our theme is pretty custom and I've tried some different variations of liquid code, but to no avail.
collection page navigation with tag needed to hide
I've attached a screen shot highlighting the tag we need to hide from the nav.
Here is the URL to that page: https://mycuisinesolutions.com/collections/all
Here is the code which dynamically pulls in all tags for that nav:
{% if collection.all_tags.size > 0 %}
<div class="tags">
{% for tag in collection.all_tags %}
{% capture tag_slug %}{{ tag | handleize }}{% endcapture %}
{{ tag }}
{% endfor %}
</div>
{% endif %}
If anyone could be of assistance or needs more information, please let me know.
I've tried adding
{% unless product.tags contains 'no-quantity' %}
--tag code above--
{% endunless %}
but this did not work. Any help is much appreciated!
You're trying to check the product.tags on some reason. You need to check the tag itself in the loop. The below code should work for you.
{% if collection.all_tags.size > 0 %}
<div class="tags">
{% for tag in collection.all_tags %}
{% capture tag_slug %}{{ tag | handleize }}{% endcapture %}
{%- if tag_slug == "no-quantity" -%}
{%- continue -%}
{%- endif -%}
{{ tag }}
{% endfor %}
</div>
{% endif %}

How to delete the odd attributes while rendering form

I rewrite some widgets in bootstrap_3_layout.html.twig and I don't want the form fields to have some attributes while they are rendered.
I've found out the sequence of some widgets
button_widget → button_row → form_widget → widget_attributes
And I made a little change
{% block widget_attributes %}
{% spaceless %}
{# bla-bla-bla #}
{% for attrname, attrvalue in attr %}
{% if attrname in ['placeholder', 'title'] %}
{{ attrname }}="{{ attrvalue|trans({}, translation_domain) }}"
{% elseif attrname not in ['first','last','data-help'] %}
{{ attrname }}="{{ attrvalue }}"
{% endif %}
{% endfor %}
{% endspaceless %}
{% endblock widget_attributes %}
But it doesn't work for buttons.
I'm not sure what you are achieving but you can intercept the odd index of a twig loop as follow:
{% for attrname, attrvalue in attr %}
{% if loop.index is odd %}
odd
{% else %}
even
{% endif %}
{% endfor %}
More info on loop variable and odd test function.
Hope this help
It's strange, but the form layout in twig_bridge has some widgets to work with attributes.
1. for inputs `widget_attributes`
2. for buttons `button_attributes`
3. for another element `widget_container_attributes`
For each widget, there are next blocks in twig-bridge:
{name_of_widget}_widget - main block to render an element
{name_of_widget}_label
{name_of_widget}_row
And for attributes, there are
widget_attributes
widget_container_attributes
button_attributes
attributes
I just used incorrect one :)
Thank all for your patience.

Render tag label only if there are tags

I want to render the “Tags:” label only if the post has actual tags. When I write
{{post.tags | size}}
I get the number of tags. However, if I put it in an {% if %} condition:
{% if post.tags | size != '0' %}
it always yields true. I worked around this problem with
{% capture tagsize %}{{post.tags | size}}{% endcapture %}
{% if tagsize != '0' %}
but it seems very ugly. Is there a better way to do this?
Note: I use GitHub Pages, so using a plugin – other than being an overkill – is not an option. My Jekyll version is 2.0.4 as specified here as of date.
By default {{ post.tags }} == empty array.
As we cannot do {% if post.tags != [] %}, we just add array: [] in _config.yml.
We can now do :
{% if post.tags != site.array %}
Do something
{% endif %}
tag size returns an integer and not a string so you should compare against 0 and not '0'
{% if page.tags.size != 0 %}
<!-- some code to render tags -->
{% endif %}

Breadcrumbs in liquid

I am trying to add breadcrumbs for my product pages on an ecommerce store. I need some help with the liquid syntax.
I want to include the first product tag as a part of the breadcrumb, unless the tag is 'stickers', 'stationery', or 'accessories', in which case I would like to use the second tag. If the second tag is also either 'stickers', 'stationery', or 'accessories', I would like to use the third tag, and so on.
Perhaps a better way to say this would be: I would like to call the first available tag that isn't either 'stickers', 'stationery', or 'accessories'.
The closest I have gotten is this:
{% if product.tags.first contains 'stickers' or product.tags.first contains 'stationery' or product.tags.first contains 'accessories' %}
<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><span itemprop="title">{% if product.tags.size > 0 %}{% assign words = product.tags.last | split: '-' %}{% for word in words %}{% if word == 'and' %}{{ word }} {% else %}{{ word | capitalize }} {% endif %} {% endfor %}{% endif %}</span></li>
{% else %}
<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><span itemprop="title">{% if product.tags.size > 0 %}{% assign words = product.tags.first | split: '-' %}{% for word in words %}{% if word == 'and' %}{{ word }} {% else %}{{ word | capitalize }} {% endif %} {% endfor %}{% endif %}</span></li>
{% endif %}
This is inelegant, but it works up until a point. The point at which is breaks down is when both the first and last tags fall into one of the categories I wanted to exclude.
As far as I can see, there doesn't seem to be an option to call something like "product.tags.second" (only "first" and "last" seem to work).
I am a little out of my depth and would really appreciate some advice on how to sort this out.
The platform I'm on is Shopify.
Thanks!
Here's a couple of ways you could approach it:
<!-- 1. Loop through the product tags to find the first tag you want included in the breadcrumb -->
{% assign found_tag = false %}
{% assign tag_for_breadcrumb = '' %}
{% for tag in product.tags %}
{% if found_tag == false and tag != 'stickers' and tag != 'stationery' and tag != 'accessories' %}
{% assign tag_for_breadcrumb = tag %}
{% assign found_tag = true %}
{% endif %}
{% endfor %}
{{ tag_for_breadcrumb }}
<!-- 2. Convert the tags array into a string, remove the tags you don't want, and then get the first tag from those remaining -->
{% assign tag_string = product.tags | join: ' ' %}
{% assign filtered_tag_string = tag_string | remove: 'stickers' | remove: 'stationery' | remove: 'accessories' %}
{% assign filtered_tag_array = filtered_tag_string | split: ' ' %}
{{ filtered_tag_array.first }}