Hugo Theme Academic: Rename "interests" in about section - r

I'm setting up a Hugo website, theme academic, in R via hugodown. In the "about" section is a column named "interests" which I want to rename into "work".
What I have done so far:
The content/authors/admin/_index.md file contains following code:
interests: # <- I want to rename this into 'work'
- Artificial Intelligence
- Computational Linguistics
- Information Retrieval
If only this file is renamed then the whole column "interests" won't show.
There is another file layouts/partial/widgets/about.html which contains the following code:
{{ with $person.interests }}
<div class="col-md-5">
<h3>{{ i18n "interests" | markdownify }}</h3>
<ul class="ul-interests">
{{ range . }}
<li>{{ . | markdownify | emojify }}</li>
{{ end }}
</ul>
</div>
{{ end }}
Additional to the above change, naming with $person.interests into with $person.work will show the column again, but it is still called "interests". When additionally changing the i18n "interests" in the <h3> tag into i18n "work" the heading "interests" is removed and only the content of the column is displayed without a heading.
It seems like the new column name "work" has to be registered somewhere else, before it is properly display.
Any help appreciated.

After fiddling around I found the answer to my question. As I expected there is a file in which all ids and their translation are registred. It depends on the choosen language. If the chosen language is English en then it is enough to go to the folder: themes/academic/i18n/ and open the file en.yaml. Here we find:
# About widget
- id: interests
translation: Interests
This can be changed to:
- id: interests
translation: Work
Now the website will properly display "Work" instead of "Interests" on the About widget page.

Related

Include handlebars partials when they exist based on context in Ghost

I've got a customized theme for Ghost. I nave a guest author once on a while. I'd love the ability to include any number of custom links to the authors page for each author.
I'm aware of the authors-{{slug}}.hbs convention I could use to create a complete custom page for each author, but that's a nightmare to maintain.
Instead I was trying to try to include a partial when it exists. According to the handlebars docs the {{#> partial }} should work. But that works when I know the exact name of the partial.
I need the name of the partial to be dynamic based on the context. In my case the ghost slug for the author. According to the handlebar docs I need to pass in a function...
I tried a few ways, but gscan dislikes all of them:
{{#> (concat "partials/socials-" slug) }}
{{#> (concat "partials/socials-" (lookup . 'slug')) }}
{{#> concat "partials/socials-" (lookup . 'slug') }}
{{#> "partials/socials-{{slug}}" }}
{{#> partials/socials-{{slug}} }}
All give me:
Checking theme compatibility...
Your theme has 1 error!
----
Errors
------
Important to fix, functionality may be degraded.
- Error: Templates must contain valid Handlebars
Files: author.hbs
Have you used content blocks before? They're a way to re-use template code but still allow for customisation, it's a method used in Casper which you've forked from. Check out these lines here in page.hbs: https://github.com/jessehouwing/jessehouwingnl-Casper/blob/customized/page.hbs#L58-L65
as well as this line shown in default.hbs: https://github.com/jessehouwing/jessehouwingnl-Casper/blob/customized/default.hbs#L127
What you could do is create a custom author template that inherits the existing author.hbs template. For this example I'm going to create a custom author page for the author 'ghost' by creating author-ghost.hbs:
{{!< author}}
{{#contentFor "links"}}
<ul>
<li>Example link</li>
<li>Example link</li>
<li>Example link</li>
</ul>
{{/contentFor}}
The above code inherits author.hbs and creates a block called links. Then in the original author.hbs template we can add the block reference to where we want the contents of the block to appear:
{{{block "links"}}}
Not only will this insert the code in the custom author template, but it'll also gracefully fallback to no output if there isn't a custom author template for the author.
Hope this helps!
I had the same issue and here how I solved. Just use the lookup in this syntax.
{{#foreach navigation}}
<li class="nav-{{slug}}">
<a href="{{url}}" class="social-link" target="_blank" rel="noopener">
{{>(lookup . 'slug')}}
</a>
</li>
{{/foreach}}

Theming Drupal 8 - Loop through all posted articles and print specific section

I am trying to create my first Drupal 8 theme. On the frontpage, I want to list all articles with the title, summary, date posted, etc.
I more or less achieved this using views. Basically {{ page.content }} in twig, but found it to be really inflexible and I didn't really get the results that I wanted. What I want to do is just to iterate through all the articles and print each section of that article "manually". For instance:
{% for page in pages %}
{{ page.content.title }}
{{ page.content.datePosted }}
{{ page.content.body }}
{% endfor %}
So that I can have more control of what is happening and not making a lot of configuration in the views module when deploying. What is the best soltuion to achieve this? Thanks!
I recommend to use Views. Configure you view (filter by content type, etc.), you have a lot of parameters to achieve what you need.
Set the view to show "Content" and give it a view mode (you can use the default teaser, full, or create your own view mode). Then you can create a custom template for this :
node--xxxx--teaser.html.twig
In order to know how to name your custom template file, enable Twig Debugging in sites/default/services.yml. Set the debug variable to true. And clear cache. Then, you will see in source code the template name suggestion like this :
<!-- FILE NAME SUGGESTIONS:
* node--1--full.html.twig
* node--1.html.twig
x node--oeuvre--full.html.twig
* node--oeuvre.html.twig
* node--full.html.twig
* node.html.twig
-->
In your twig, you can do that kind of templating :
{{ content.my_field_image[0] }}
<h2>{{ node.title.value }}</h2>
<p>{{ content.body }}</p>

Symfony EasyAdmin - How to create custom field in form, displaying text informations

I am not sure, how to implement quite simple text field, into the configured form template. I have configured individual fields at yml file.
But what if I want, in the middle of the form, some text formatted informations (fetching data from another entities).
I have learned how to make custom edit template for the entities, by overriding "app/Resources/views/easy_admin/Entity/edit.html.twig".
But it allows me to change the template only around the form fields. The actual form is rendered by "{{ form(form) }}".
So, I need to edit this form() creation or customize the template somehow.
Is the only solution for this custom text field, to create custom form field type in Symfony? Or are there other methods to achieve this?
hope this helps
in the .twig file:
{% for name in value %}
<li>
<span>{{ include('#EasyAdmin/default/edit.html.twig', { value: name.name }) }}</span>
</li>
{% endfor %}
it means that the variable $name (collection) entered from the entity should be displayed inside this "for loop"
you can use the same technique to parse your desired html content
[edit.html.twig is located in app/Resources/views/easy_admin]

How to get the field_image path with Twig in Drupal 8

To make an animated slider, I overwrite a fields view template file in my own template named: views-view-fields--slider.html.twig
Inside that file I have access to a fields array to print out all the fields that are in my content-type slide.
The problem is that I need to get the path of the image file instead of the image itself, because I need the path for CSS background-image styling.
The following doesn't work:
<div class="jumbotron " ref="" style="background-image:url(?????);">
{{ file_url(fields.field_image.entity.fileuri) }}
</div>
I tried everything I good find on Google:
fields.field_image.entity.uri
fields.field_image.entity.uri.value
fields.field_image.entity.url
fields.field_image.entity.url.value
etc.
Has anyone an idea how it is done in Drupal 8 ?
Since you are in views-view-unformatted you should already have access individualy to each field of your content type Slide with {{ row.content }} and because of that you have to do:
{{ file_url(row.content.field_image.entity.fileuri) }}
Try {{ file_url(row._entity.field_image.entity.uri.value) }}.
It works for me.
<div style="background-image:url({{ file_url(row._entity.field_image.entity.uri.value) }});"></div>
I found this module: image_url_formatter, so in View interface, I can use this to formatter my image filed as path.
It works perfect, but if I turned the twig debug on, it wouldn't work, because it will output debug annotation. I don't know how to solved it yet.
I use fields.field_image.content to show the path, I don't konw whether it's rignt.
Solution without extra module:
In your Views:
1.Add your image filed to the Advanced/Relationship
2.Then in the filed section, change to File Group, you can see URI field,add it, and make sure you check "Display the file download URI"
3.Add your new field in the twig template: {{ field.uri.content }}
Done!

Adding a link inside translated content in Twig template

Inside a Twig template I would need to have a translated text that contains a link (the path should be generated by the Router, not statically embedded).
Twig does not allow to render a variable inside a trans block - I'm also aware of the following:
{% trans with {'%name%': 'Fabien'} from "app" %}
Hello %name%
{% endtrans %}
but I can't see how to use that to inject inside the translation a piece like this
privacy policy
(of course, the anchor text should be translated as well)
The approach I've taken is this:
In the translation file:
page.privacy.policy: Please read our %link_start%privacy policy%link_end%
In the twig file:
<p>{{ 'page.privacy.policy' | trans({'%link_start%' : '', '%link_end%' : ''}, 'account') | raw }}</p>
I'm not sure if this can be done using the block syntax you mentioned above as I found it didn't work unless I piped the result of the translation through the 'raw' filter. Also I use message domains to split the translations, hence the 'account' parameter.
I think the closest to your example would be:
<p>{{ 'Please read our %link_start%privacy policy%link_end%' | trans({'%link_start%' : '', '%link_end%' : ''}) | raw }}</p>
EDIT:
The only issue with this approach I've come across is where I need to programmatically follow a translated link in a unit test as there isn't a single translation representing the link text. Although messy I think it would be possible to get round this by providing a separate translation for the link text and substituting it's translated value into the full text as an additional variable.
rebdirdo's solution is not really safe as it's not escaping whole message. It is not working correctly for messages like "don't use <b> tag, use <strong> tag instead. %link_start%Here%link_end% you can find why.", because the tags will be not escaped and will be not visible.
working approach:
translation file:
advises.strong: don't use <b> tag, use <strong> tag instead. %link_start%Here%link_end% you can find why.
twig file:
{{ 'advises.strong'|trans|nl2br|replace({'%link_start%': '', '%link_end%': ''})|raw }}
Note the nl2br filter. It is necessary to put some filter there to make the raw filter working only for the link tags.
This is a better way:
{{ 'Please read our %privacy_policy%'|trans({
'%privacy_policy%': ' ' ~ 'Privacy Policy'|trans ~ ''
})|raw }}
Twig:
{{'body.term'|trans('%link_terms%' :app.request.getSchemeAndHttpHost()~path('terms')},'AcmeTerm')|raw }}
AcmeTerm.yml
body
term: >
<ul>
<li>ReadTerms.</li>
</ul>
where path('terms') is the route
like:
it__RG__terms ANY ANY ANY /it/termini-e-condizioni
en__RG__terms ANY ANY ANY /en/terms-and-conditions

Resources