I'm wanting to use Jekyll as a CMS essentially, so I would like to take the content from a post and display it in a specific area of my website.
{% for post in site.posts %}
{{ post.content }}
{% endfor %}
This displays all of the content from all of the posts, however I'd like to take content from one post at a time. I'm fairly new to Jekyll, so I'm not sure if i'm supposed to add YAML front matter into my posts and target them with a "for post in site with title_____" post.content" of sorts.
Thank you!!
{% assign thepost = site.posts | where:"slug","post_slug" %}
{% for post in thepost %}
{{ post.content }}
{% endfor %}
And on the post;
slug: post_slug
I figured it out, sorry I posted prematurely.
The answer is add a category to your post with YAML front matter and then in your include file use:
{% for post in site.categories.CATEGORYNAMEHERE %}
{{ post.content }}
{% endfor %}
Related
I am rendering a form that contains several choice fields. I want to render one specific choice field differently from the other ones.
I've tried to use:
{% form_theme form 'MyBundle:Form:my-choice-field.html.twig' %}
{{ form_widget(field) }}
But that changes the look and feel of all choice fields in that form. If I place form_theme right next to the field I want to render differently, it does nothing.
I have thought of creating a new Form Type but it seems overkilling, I just want a different style for that specific field. Any ideas?
In the doc there is a section describing how to personalize an individual field, for example to customize the name field of a product entity only:
{% form_theme form _self %}
{% block _product_name_widget %}
<div class="text_widget">
{{ block('form_widget_simple') }}
</div>
{% endblock %}
{{ form_widget(form.name) }}
Here, the _product_name_widget fragment defines the template to use for the field whose id is product_name (and name is product[name]).
You can also override the markup for an entire field row using the same method:
{% form_theme form _self %}
{% block _product_name_row %}
<div class="name_row">
{{ form_label(form) }}
{{ form_errors(form) }}
{{ form_widget(form) }}
</div>
{% endblock %}
{{ form_row(form.name) }}
I am looking for a way to exceed the 255 characters limit on product tag in Shopify admin. Please suggest any way of doing so.
In general this does not sound like a good idea. If you are trying to embed extra information per item you might want to look at putting that in a snippet file and then formatting your tag like __extra File1 and then a snippet like the following in your product template:
{% for tag in product.tags %}
{%if tag contains '__extra' %}
{% assign snip = tag | remove_first : '__extra ' %}
{% include snip %}
{% endif %}
{% endfor %}
This would allow you to share large chunks of information per product while not blowing up your tags.
If you adopt this approach then you'll also want to go through your theme and make sure you filter out tags beginning with '__'. e.g.
{% for tag in collection.all_tags %}
{% assign tag_pref = tag | slice:0,2 %}
{% unless tag_pref == '__' %}
... do your tag related layout
{% endunless %}
{% endfor %}
Problem
Recently I added tag support for my personal blog, but I am not happy with a way that it was done.
Blog uses jekyll with github-pages, so my solution has many limitations that platform comes with.
In order to create tag javascript I created file tag/javascript/index.html with following content:
---
layout: tag
tag: javascript
---
And it in my tag layout file I have following code:
---
layout: default
---
<div class="tag-header">
posts related to <strong>{{ page.tag }}</strong>
</div>
{% for post in site.posts %}
{% if post.tags contains page.tag %}
<section class="post">
<header>
{{ post.title }}
</header>
<time>
{{ post.date | date_to_string }}
</time>
<summary>
{% if post.excerpt %}
{{ post.excerpt }}
read more
{% endif %}
</summary>
<div class="tags">
{% for tag in post.tags %}
<span>
#{{ tag }}
</span>
{% endfor %}
</div>
</section>
{% endif %}
{% endfor %}
Result is something like this posts related to javascript.
Question
How can I automate tag creation process, so it does not require manual tag file creation (tag/javascript/index.html from sample)?
Notice
I have read An easy way to support tags in a jekyll blog already, and the only working solution for github-pages was this one, which I don't like, because it puts all tags in one page.
Additionally note that I am using github-pages, so custom plugin is not an option.
You can find full sources here.
Current Jekyll (3.1.x) cannot generate tag page automatically. You need to use a custom plugin. But you don't want to.
Why ? It's not so difficult to change deployment process on github pages.
You can store you code in master and you generated page in gh-pages. This answer will give your more information on how to do it.
I have this :
template edit.html.twig
{% extends "....:...:layout.html.twig" %}
{% block body %}
{{ render(controller('EVeilleurFlowerBundle:Catalogue:add' )) }}
{{ render(controller('EVeilleurFlowerBundle:Catalogue:delete' )) }}
{% endblock %}
And the template "add" is basically a single form.
When the user enters "wrong" data in the add form, it automatically redirects to add.html.twig, displaying a single form ( wtih the error ) without layout, css etc...
Can i change the redirection, or am I building my templates the wrong way ? (pretty much newbie here :) )
Thanks
I have a project in Symfony2 where I have lots of different forms that do lots of different things and one thing I am struggling with at the moment is working out how I can set two different templates to handle form_rows.
I have specified one form_row template in a fiels.html.twig file that handles form rows as follows:
{% block form_row %}
{% spaceless %}
<div class="form-element{% if errors %} form-element-error{% endif %} widget-group clearfix">
<div class="widget widget-1-of-3">
{{ form_label(form) }}
</div>
<div class="widget widget-2-of-3">
{{ form_widget(form) }}
{% if errors %}
<small>{{ form_errors(form) }}</small>
{% else %}
{% if help is defined %}
<small>{{ help }}</small>
{% endif %}
{% endif %}
</div>
</div>
{% endspaceless %}
{% endblock form_row %}
This works great for me for general forms, but I also have a number of form elements that I have in tables as well. This is generally for groups of form data that I am updating.
In this case I then want to be able to specify using a different form_rows template.
I understand that I could specify the row via the field name or group, but I have a lot and I just want a more general way of doing this.
Does anyone know how this could be achieved.
You can have a lot of form themes defined in different templates.
Just add in your twig file on the top where you want to use theme:
{% form_theme form 'AcmeDemoBundle:Form:fields.html.twig' %}
{{ form_widget(form) }}
where form_theme file can be any twig file with theme definition.
Now form widget is decorated with attached theme.