CMS Development

JBrower
メンバー

How to create an option to hide publish date in blog post.

解決

My customer is wanting the option to choose whether a blog post would show the publish date to the user.

I figure I could do this with Javascript but was hoping to avoid content manipulation post load.

One idea was to create a module for blog post settings but I don't know if I can access those variables outside of the module without Javascripting something.

Another option is to have something in the text of the post content that I can look for, say, at the end.  Then I can parse that in Hubl and do my magic from there, but that sounds pretty hacky. 😀

Any ideas?

0 いいね!
1件の承認済みベストアンサー
piersg
解決策
キーアドバイザー

How to create an option to hide publish date in blog post.

解決

Hi @JBrower, I would add a boolean field to your blog template, which will show up in a blog post's editor, and then hide/display based on that:

 

<!--
   templateType: blog
   isAvailableForNewContent: true
   -->
{% boolean "hide_date" label='Hide the publish date?', value=False, export_to_template_context=True %}

{# rest of your blog template #}

 

 

Then wherever you're displaying your publish date do:

 

{% if widget_data.hide_date.value == false %}
    {{ content.publish_date|datetimeformat('%e %B %Y')}}
{% endif %}

 

 

This will work if you have your publish date in a blog post hero module that is imported into your blog template or used directly in the blog template.

元の投稿で解決策を見る

5件の返信
piersg
解決策
キーアドバイザー

How to create an option to hide publish date in blog post.

解決

Hi @JBrower, I would add a boolean field to your blog template, which will show up in a blog post's editor, and then hide/display based on that:

 

<!--
   templateType: blog
   isAvailableForNewContent: true
   -->
{% boolean "hide_date" label='Hide the publish date?', value=False, export_to_template_context=True %}

{# rest of your blog template #}

 

 

Then wherever you're displaying your publish date do:

 

{% if widget_data.hide_date.value == false %}
    {{ content.publish_date|datetimeformat('%e %B %Y')}}
{% endif %}

 

 

This will work if you have your publish date in a blog post hero module that is imported into your blog template or used directly in the blog template.

RFougere
メンバー

How to create an option to hide publish date in blog post.

解決

Hi there. I am looking for this same solution. Would you mind telling me exactly where in the template this code goes? I'd appreciate it. Cheers!

0 いいね!
piersg
キーアドバイザー

How to create an option to hide publish date in blog post.

解決

I tend to put these global template variables at the top before the opening <!doctype html>. Use the if statement wherever you need it.

0 いいね!
RFougere
メンバー

How to create an option to hide publish date in blog post.

解決
Sorry for the delay, and thank you so much for this! Cheers, Randy
0 いいね!
JBrower
メンバー

How to create an option to hide publish date in blog post.

解決

Wow, I did not know about the "export_to_template_context" attribute.  Thank you!