Access params does not work in if condition

Hey,
I have the following code:

{{ if (and ($.Site.Params.ShowReadingTime) (eq .Params.identifier "overview")) }}
{{ else if ($.Site.Params.ShowReadingTime) }}
<span class="post-read-time"
    >— {{ .ReadingTime }} {{ $.Site.Params.MinuteReadingTime | default "min read" }}</span
  >
{{ end }}

But the first if gets never executed and I do not understand why. The if-else will get executed.

When I switch the cases, then the part with the logical and will still not get executed so it has to do with the condition. I think it has to do with the eq part, but I do not see the mistake.

My front matter looks like that:

---
title: "Math"
identifier: "overview"
date: 2022-02-28T11:41:53+01:00
draft: false
---
{{ if (and ($.Site.Params.ShowReadingTime) (eq .Params.identifier "overview")) }}

ShowReadingTime in your config's [params] section is set (to something other than false)

AND

the frontmatter of your page has

identifier: overview

set.

In that case it's shown.

{{else if ($.Site.Params.ShowReadingTime)}} 

{{ end }}

To help you we would have to know what your config and your test pages frontmatter is saying.

1 Like

Ah yes sure.

Here is my config.toml:

baseURL = 'https://websitename'
languageCode = 'en-us'
title = 'Miguels Blog'
theme = 'hello-friend'
enableEmoji = 'true'

[params]
contentTypeName = "blog"
showReadingTime = true
showMenuItems = 3

[languages]
  [languages.en]
  readOtherPosts = "Read other posts"
  lastModDisplay = "Modified:"
  [languages.en.menu]
      [[languages.en.menu.main]]
        identifier = "books"
        name = "Books"
        url = "/books/readings"
      [[languages.en.menu.main]]
        identifier = "math"
        name = "Math"
        url = "/math/"
      [[languages.en.menu.main]]
        identifier = "about"
        name = "About"
        url = "/myself/about/"

The page where I try to use the identifier has this frontmatter:

---
title: "Math"
identifier: "overview"
date: 2022-02-28T11:41:53+01:00
draft: false
---

Or what did you mean with test page frontmatter?

That’s what I meant. But from what I can see I would expect that to work.

Now check the “context”. The dot (.) does not always mean “the current page” if you are inside of a range or with construct. You will have to show more code. Maybe a public repo?

By the way, your config variable is showReadingTime, not ShowReadingTime. I don’t expect that to be the solution but test it :wink:

GitHub - m1guelperez/PersonalBlog: Sourcecode for personal blog. Here is the repo :slight_smile:
Changing ShowReadingTime to showReadingTime did not change anything. In the theme doc it is actually stated as showReadingTime

The file I am talking about is in themes/hello-friend/layouts/_default/list.html

It seems like:

{{ if (and ($.Site.Params.showReadingTime) (eq $.Params.identifier "overview")) }}

but I do not know why the others do not work :thinking:

Which one is the content file you expect the if-rule to apply?

The content/math/_index.md

hmm… all those pages come up white for me. I have the distinct feeling I don’t know how to initialise your repo :wink: I did run git submodule update --recursive --remote but it didn’t do anything… help me to help you?

edit:

got it…

git submodule update --init --recursive

Ah damn! :smiley:

Hmm… So adding the following:

          {{ if (and ($.Site.Params.showReadingTime) (eq $.Params.identifier "overview")) }}

SCHWAH SCHWAH

          {{else if ($.Site.Params.showReadingTime)}}
          <span class="post-read-time"
              >— {{ .ReadingTime }} {{ $.Site.Params.MinuteReadingTime | default "min read" }}</span
            >
          {{ end }}

leads to the following at http://localhost:1313/math/

So I would say it’s working as expected. What did you expect where? That page is set to “identifier = overview” and it’s showing the schwah schwahs from my override… Please do something along the lines of “I load localhost:1313/so-and-so” and expect to see “this and that”. I think you either have a “polluted” installation (then delete everything and re-setup) or you are working on the wrong side of your setup.

@Anony

When posting blocks of code in this forum, use markdown code fences (tripple backticks).

When posting inline code in this forum, use single backticks.

I have edited your posts.

1 Like

I had to wait for 18hours to answer you because I am a newbie uff.

Your solution is what I currently have as well and that was my goal. But before I could not get rid of the date and readMore button.

So my issue from the beginning is already solved, as I said in the edit of my 3rd post.

However, do you know if it is possible to make two different texts like the SCHWAH SCHWAH?
Here SCHWAH SCHWAH is applied under mathematical journey and proofs.

How could I make two different texts? One only for proofs and one for mathematical journey?

Thank you and sorry!