How to display an image from the user module in PyroCMS? - html

I'm trying to get the image URL which is stored in the user module, using the following code:
{{ user:profile user_id="3" }}
{{ display_name }}
{{ company }}
{{ profile_picture }}
{{ /user:profile }}
{{ profile_picture }} is the image and all that appears as 'Array' on the page. The other variables appear as I would like them to, images have just been giving me problems. The image is properly store in the File module, I just can't seem to get it to appear on the page.
Any help would be appreciated

profile_picture is an array. You'll have to access the subelement of image if you want the image URL.
{{ user:profile user_id="3" }}
{{ profile_picture:image }}
{{ /user:profile }}

Related

Hugo/Docsy: execute of template failed at <.url>: can’t evaluate field url in type bool

I am developing a static web application using Hugo with Docsy theme. I would like to add an condition within Docsy Partials code where I would like to append the mailTo: word to my .url if the .mail is set to true, when I try to do this then I get the following error:
/themes/docsy/layouts/partials/footer.html:36:34": execute of template failed at <.url>: can’t evaluate field url in type bool
Following is the code I am adding to my partials:
{{ $myUrl := "" }}
{{ with .mail }}
{{ $myUrl = print "mailTo:" .url }}
{{ else }}
{{ $myUrl = .url }}
{{ end }}
{{ $myUrl }}
If I add some test then everything would work perfectly:
{{ with .mail }}
TRUE
{{ else }}
FALSE
{{ end }}
I am quite new to the Hugo and Docsy theme so finding difficult to understand and fix it. Any help would be really appreciated.
You are not using with correct here: https://gohugo.io/functions/with/. I think you should use if here.

In Jekyll, how do I render custom metadata for a collection?

I have the following in my _config.yml file:
collections:
nr_qa:
output: true
permalink: /:collection/:name
title: 'Node-RED Questions and Answers'
descriptions: 'Node-RED is a flow-based (visual) programming tool. These pages have some information that may be currently missing from the documentaiton.'
github_pages:
title: 'GitHub Pages and Jekyll/Liquid'
description: 'Hints and tips on using Jekyll for publishing to GitHub Pages.'
output: true
permalink: /:collection/:name
and I want to create an automatic index for my collections. So I use code like this:
## {{ site.collections.github_pages.title }}
{{ site.collections.github_pages.description }}
<ul>
{% for item in site.github_pages %}
<li>
{{ item.title | replace:'_',' ' }}
<p>{% if item.description %}
{{ item.description }}
{% else %}
{{ item.excerpt | strip_html }}
{% endif %}</p>
</li>
{% endfor %}
</ul>
And yes, I know I've rather mixed up my markdown and html there. Not relevant to this question.
The problem is that {{ site.collections.github_pages.title }} and {{ site.collections.github_pages.description }} don't render anything even though I think they should.
Can anyone point out my mistake please?
The problem is that title and description should be included in each collection, and not in _config.yml.
Check out Accessing Collection AttributesPermalink for further details.
update
title can be present in each collection metadata in _config.yml. The problem is how you are accessing those variables.
One approach is to have a specific layout for each collection, then you can access them like:
{% assign col = site.collections | where: 'label','github_pages' | first%}.
TITLE: {{ col.title }}.
DESCRIPTION: {{ col.description }}.

Jekyll site.categories incorrect values

When I access site.categories.first I get what looks to be all the content of all my blog posts wrapped into a single string.
When I access site.categories[1] I get an empty string. The length of site.categories appears roughly equal to the number of categories I have.
I checked for any manual editing of site.categories, but I don't see anything that would be doing this.
You can use inspect filter to understand how categories works.
{{ site.categories | inspect }} returns a hash like:
{
"jekyll"=>[#<Jekyll::Document _posts/2017-10-31-welcome-to-jekyll.markdown collection=posts>],
"update"=>[#<Jekyll::Document _posts/2017-10-31-welcome-to-jekyll.markdown collection=posts>]
}
And {{ site.categories.first | inspect }} returns an array like :
["jekyll", [#<Jekyll::Document _posts/2017-10-31-welcome-to-jekyll.markdown collection=posts>]]
Where {{ site.categories.first[0] }} is the category name, and {{ site.categories.first[1] }} is an array containing first category's document.
You can call a category from his name {{ site.categories.jekyll | inspect }} but not by is index {{ site.categories[0] | inspect }} => []
You cannot modify site.categories because it is freezed by jekyll.

Jekyll: Liquid filter "cgi_escape" returns error for some variables

The short version: have you managed to use something like {{ page.title | cgi_escape }} in an {% include %}-ed partial?
Details follow:
I have a partial that I use like so:
{% include mainContainer.html %}
Works fine. Then, in that partial, try to display some liquid variables:
{{ page.title }} displays the title.
{{ page.content }} Displays the content.
{{ page.content | cgi_escape }} displays the content, but escaped.
{{ page.title | cgi_escape }} doesn't work at all. Creates the following error:
Liquid Exception: undefined method `encoding' for nil:NilClass
Aside from {{ page.content }} I get the error for any of the {{ page }} variables (category, title, etc) but all of them will display fine without the filter. Also, {{ page.title | cgi_escape }} works okay in the...uhhh...'content' part of the layout (I'm not sure what to call it--the {{ content }} section). I only seem to get the error with {% include %}
Nevermind. The build was failing because a few of the pages using {% include mainContainer.html %} didn't have any front matter and thus no page.title (or whatever). Apparently, Liquid is willing to let {{ page.title }} pass if the variable isn't set, but not {{ page.title | cgi_encode }}

Why won't js assets combine / load with PyroCMS in production?

{{ asset:js file="theme::custom.js" group="default" }}
{{ asset:js file="theme::app.js" group="default" }}
{{ asset:render_js group="default" }}
{{ asset:render_js group="modules" }}
That's my code for my JavaScript, but when I load in production, it doesn't load the script tag. However, in system/cms/config/asset.php if I turn asset_min and asset_combine to false, then it loads the JS files individually, without combining or minifying.
But I want it to combine and minify.
Help?
You have to do has follow to render the JS assets :
{{ asset:js file="theme::custom.js" group="default" }}
{{ asset:js file="theme::app.js" group="default" }}
{{ asset:render group="default" }}
{{ asset:render group="modules" }}
I think asset:render_js don't actually works
I have been having a similar problem.
It turns out {{ asset:render_js }} doesn't work, however <?php Asset::render_js(); ?> does.
So, for anyone else having problems in PyroCMS 2.2 using render_js, try the following:
{{ asset:js file="theme::javascript_file.js" }}
<?php Asset::render_js(); ?>