In pyrocms admin, I have created a image field under default.I would like to pull that field in a page.
Currently my code looks like this
{{ if page:slug == "contact" }}
<img src="{{ template:contact_main_image:img}}"> //the field name is contact_main_image
{{ endif }}
but I can't see the image.
Related
I am trying to display an image in my post list.
In order to achieve that I added some tags in my post.md:
---
title: "Hello"
header_image: /images/blog/2019/water.jpg
images: /images/blog/2019/water.jpg
resources:
src: /images/blog/2019/water.jpg
title: "The image I want"
---
Then I edited list.html and tried different things:
{{ define "main" }}
<div class="archive animated fadeInDown">
<ul class="list-with-title">
<div class="listing-title">{{.Title}}</div>
{{ range .Pages }}
<ul class="listing">
<div class="listing-item">
<div class="listing-post">{{ .Title }}
{{ with .Resources.ByType "image" }}
<div class="Image">
{{ range . }}
<img src="{{ .RelPermalink }}">
{{ end }}
</div>
{{ end }}
{{ $.Param "header_image" }}
-- {{ range .Page.Resources }}
THERE IS ONE ITEM => NOT WORKING
{{ end }} <<
<div class="post-time"><span class="date">{{.Date.Format "Jan 2" }}</span></div>
</div>
</div>
</ul>
{{ end }}
</div>
{{ end }}
But when I try to display Resources, I always get [] (nothing)
Any idea what I am doing wrong?
I don't think your {{ $.Param "header_image" }} is working, either.
The way to access your custom, non-standard variables on pages, as well as sites, is through the .Params object, e.g. .Params.header_image. Note the small letter at the beginning, as opposed to capital letters for built-in params.
Page-level params on the Hugo Docs
Custom page params
To access
---
header_image: /images/blog/2019/water.jpg
---
you can use this in your page template.
{{ .Params.header_image }}
Resources
Page resources on Hugo Docs
It seems that resources is actually an array of objects, and with yaml, you should actually have something like this (note the dash):
resources:
- src: /images/blog/2019/water.jpg
title: "The image I want"
Also mind that this feature seems to only be available only for page bundles
Debugging
You can use {{ printf "%#v" .Resources }} for debugging.
I've got a blade view in which I load another string via a function called retrieveSomeContent()
retrieveSomeContent() returns a string, which could hold 'references' like {{ $action->url }}. The data itself is available in the view.
// myView.blade.php
// simplified
...
{{-- doesn't work
displays {{ $action->url }}
--}}
{!! retrieveSomeContent('section1B') !!}
{{-- works --}}
{{ $action->url }}
...
Off course the view right now will just displays {{ ... }} as text instead of parsing it to http://......
How would I be able to parse the string generated via retrieveContent()?
I am setting up a GitHub page which uses Jekyll. I know how to create a new post, new page. I wanted a new "posts" like the page, wherein I can add posts which I want to. So there will be a posts page (by default) and there will be some other page say blog, both of which shows some posts in the appropriate category.
You can create a page which lists all posts which have a certain category or tag.
Example code from the link:
---
layout: page
---
{% for post in site.categories[page.category] %}
<a href="{{ post.url | absolute_url }}">
{{ post.title }}
</a>
{% endfor %}
If the .md files you are talking about aren't posts, you can use Collections.
Here's example code from the link tailored to your xyz example - basically, you define your collection in the config file:
collections:
- xyz
Then, you create .md files in an _xyz folder, and you can display a list of them like this:
{% for item in site.xyz %}
<h2>{{ item.title }}</h2>
<p>{{ item.description }}</p>
<p><a href = "{{ item.url }}" >{{ item.title }}</a></p>
{% endfor %}
Hi I have twitter api working to output details on the page however, this
field:
{{ $item['text'] }}
Gives me something like this:
RT #JacksSmokehouse: Don't forget #HappyHour tomorrow until 6pm - #loveJacks #live_oldham #OldhamHour #YouDontKnowJack https://twitter.com/shorturl, (with t.co)
So the image https:// I want to actually display it? is it possible to write in blade template a regex, something like this:
for each {{$item['text']}} take the url if there is any and output it below the text? can be a different variable.
Here's my full code:
<div>
#if(!empty($twitterItems))
#foreach($twitterItems as $key => $item)
{{ $item['text'] }}
#if(!empty($item['extended_entities']['media']))
#foreach($item['extended_entities']['media'] as $image)
<img src="{{ $image['media_url_https'] }}" style="width:100px;">
#endforeach
#endif
{{ $item['favorite_count'] }}
{{ $item['retweet_count'] }}
{{ $item['created_at'] }}
#endforeach
#else
There are no data.
#endif
I'm Symfony2 and CreateFormBuilder to create my form.
Currently I'm using {{ form_widget(form) }} to display the form.
My entity have path property that is the path of an image save on filesystem.
I want to display the image in the form (with a <img> html tag), how can I achieve this result? Should I handle the form in my template field by field? Or is there a way to own only one field in the template and render the other ones with {{ form_widget(form) }} ?
What you could do is handling the form field by field, and display the image if the value is set.
Let's say you have a field name image. In Twig, you can access its value through form.vars.value.image. Then, it's quite easy to display an img tag:
{% if form.vars.value.image is not null %}
<img src="{{ asset('upload/dir/' ~ form.vars.value.image) }}" />
{% endif %}
Here, upload/dir/ is a path where you store your images. If you have a constant for this path, you can use it in Twig:
{{ asset(constant('Acme\\DemoBundle\\Model\\Object::UPLOAD_DIR') ~ '/' ~ form.vars.value.image) }}
An alternative could be to create your own type with its own template:
http://symfony.com/doc/current/book/forms.html#form-theming
http://symfony.com/doc/current/cookbook/form/form_customization.html
Edit: I forgot an interesting alternative. You can customize an individual field: http://symfony.com/doc/current/cookbook/form/form_customization.html#how-to-customize-an-individual-field. Here is a draft of what you could do:
{% form_theme form _self %}
{% block _object_image_row %}
<div class="name_row">
{{ form_label(form) }}
{{ form_errors(form) }}
{{ form_widget(form) }}
{% if form.vars.value.image is not null %}
<img src="{{ asset('upload/dir/' ~ form.vars.value.image) }}" />
{% endif %}
</div>
{% endblock %}