How to add an emoji to a Hugo page variable? E.g. inside the title in the following code snippet:
date = "2016-11-20T12:00:00"
draft = false
tags = ["Fun"]
title = "Went sporting :heart:"
Hugo has two ways of handling Emojis.
Setting enableEmoji=true in your site config will handle emoji syntax like :heart: in your markdown content.
For titles etc. you must use the emojify template func, so in your template:
{{ .Title | emojify }}
Related
I've used the hugo-icon single page theme to build a static site and have been asked to add a new page for product descriptions. I have read many tutorials/answers on stack and watched Mike Danes videos to date but cannot get a new page to render.
When I run the following command hugo new products/product1/_index.md a url to product1 is generated but no content is rendered. This is the content of my _index.md file;
---
title: "Product1"
date: 2021-05-24T14:47:36+01:00
draft: false
---
product1 info
I expect one of 2 things; To see 'product1 info' rendered at the url. OR I place a html file of the same name somewhere in the folder structure to render text etc. I have tried multiple locations to place html and still I cannot see anything.
Can someone explain or give an example of adding a new page to the hugo-icon theme and explain if I am missing a fundamental concept.
config:
# Main config file for icon theme.
theme = ["hugo-icon"]
baseURL = "https://www.example.com/"
languageCode = "en-ie"
title = "my site"
[params]
author = "Me"
description = "My site"
# Hero section (from here on is for icon theme)
[params.hero]
img = "images/hero_bg_green.jpg"
title = "My Site"
Thanks
I was missing this fundamental design pattern. Each folder created under layouts required a template. In my case this looked like the following where each page was designed inside the single.html file
Layouts
page1
single.html
page2
single.html
The route needs defining in the content folder inside content/pages/page-one.md like so where type is mapped to the folder name by its type definition
type : "page1"
title: "Page 1"
date: 2021-05-27T11:16:39+01:00
draft: false
My url therefore is www.example.com/pages/page-one.html which is designed in layouts/page1/single.html and mapped via the type definition to www.example.com/content/pages/page-one.md
The .md file inside content/... dictates the path to the url. The type definition dictates which page to render from layouts/...
I want to change hugo's post image.
+++
title = "how to read the book"
draft = false
date = "2017-01-25T21:39:26-06:00"
image = "book.jpg"
+++
Hello World. New Book Review.
I put book.jpg under mywebsite/static/images/ directory. But the post still using the default image.
Any suggestions?
I solved this issue by changing image = "book.jpg" to thumbnail = "images/book.jpg"
I followed the official guide from https://gohugo.io/overview/quickstart/ originally. It is very confusing.
If you're using front matter to configure your posts, follow these steps:
In your config.yaml file, make sure the cover parameters are set to not hide images
cover:
hidden: false # hide everywhere but not in structured data
hiddenInList: false # hide on list pages and home
hiddenInSingle: false # hide on single page
Add the image to the static folder (ex. meteor.png)
In your post's front matter, add the following lines to reference the image
---
title: "Impact Fanatics"
date: 2022-09-27T18:03:38-04:00
draft: false
relative: true
cover:
image: /meteor.png
---
I'm working at a project written in Ionic/Angular/Typescript. In the .html file, I have
< p> {{stringVar}} </p>
In the .ts file,I have
this.stringVar= "Visit http://www.google.com.
Visit http://www.stackoverflow.com."
I have 2 questions:
1) I want the 2 sentences in the string to be displayed in html on different lines. What should I do in order to achieve this: add \n or < br> or something like this?
2) I want the 2 links in the string to appear as links in html,too. That is,when the user clicks on them,he will be taken to those sites.
Thanks in advance!
1) To appear in different lines, you must put each one inside their own <p> tag, like this:
<p>first line</p>
<p>second line</p>
2) To appear as clickable links, you need to put in <a> tags, with url in href attribute, like this:
<p>click here to visit google.</p>
It would be better if you could change the structure of your data, to something like this:
<p ng-repeat="url in urlList">Visit {{url}}</p>
this.urlList = [
"http://www.google.com",
"http://www.stackoverflow.com"
];
or even better:
<p ng-repeat="site in siteList">Visit {{site.name}}</p>
this.siteList= [
{ name: "Google", url: "http://www.google.com" },
{ name: "StackOverflow", url: "http://www.stackoverflow.com" }
];
The best approach to go with a 'list', rather than a stringVar
this.linkList = [
"http://www.google.com",
"http://www.stackoverflow.com"
];
1) I would suggest to have <p></p> instead of <br/> in between.
2) The following is a working sample with Angular2
<p *ngFor="let link of linkList">Visit {{link}}</p>
Check the working sample here : https://embed.plnkr.co/Om3CXpT9xN07YCz2aHQr/
Both Question has one answer you Basically want to Interpolate string with html in the angular, although i am not expert in angular1.x but yes there is one service used for the same called as
$interpolate(templateString)(you_.ts/js_code);
by using this you can show your string as it as on the webpage event using html in you javascript file too. you just have to pass the html in your string ans display it in the webpage
for example lets assume your use case you simple have to add this like :-
this.stringVar= "Visit <a href='http://www.google.com'>Google</a> Here and<br> Visit <a href='http://www.stackoverflow.com'>Stackoverflow</a> Here."
and than convert this using interpolate like this
$scope.your_string = $interpolate(templateString)(stringVar);
Working Example for the same
I'm trying to use a variable within the content of a Hugo statically generated site. For example, the content looks like the following:
Go to your site's url ({{ .Site.BaseURL }})
Enter your credentials
.....(blah blah blah)
When this gets rendered, the {{ .... }} part doesn't get processed...it stays the same as I put above. I've tried it with a $ in front as well. Variables within templates seem to work just fine. Do I need to create a shortcode to use within content pages?
So it looks like a shortcode is the way to do this. For what it's worth, I changed the document to look like the following:
Go to your site's url ({{< siteurl >}})
In layouts/shortcodes, I created the file siteurl.html. It looks like the following:
{{ .Page.Site.BaseURL }}
I needed to add .Page in there to get access to the Site variables. See this Issue Report for more details.
In Hugo, When you want to use a variable in markdown (.md) file then you need to create a shortcode for that first.
You can follow these steps:-
create shortcode
layouts/shortcodes/siteurl.html
{{ .Page.Site.BaseURL }}
usage
content/post/myblogpost.md
---
# front-matter
---
1. Go to your site's url ({{< siteurl >}})
2. Enter your credentials
3. .....(blah blah blah)
result
post/myblogpost.html
1. Go to your site's url (https://codingnconcepts.com)
2. Enter your credentials
3. .....(blah blah blah)
Source: https://codingnconcepts.com/hugo/custom-shortcode-hugo/
I had the same problem, and this post helped me.
I wanted to display a site param in my site content, and discovered you cannot use regular templating inside content files.
In the end I created a shortcode to load the requested site param. Who knows this information might help someone.
/config.yml
params:
appName: My app
/content/about.html
<p>My app's name is {{< param "appName" >}}</p>
/layouts/shortcodes/param.html
{{/* Usage: {{< param "siteParamName" }} */}}
{{ index .Site.Params (.Get 0) }}
Result
<p>My app's name is My app</p>
This is an attempt to slightly improve #minitauros answer with a simplistic example to lookup a (site) parameter sub-key (aka walk the YAML tree, infer an element, etc.).
I would like Hugo to have a JSONPath or jq syntax and, obviously, this example is far from competing with either solutions.
config.yml
params:
mode: one
support:
mailing: info#example.net
layouts/shortcodes/param.html
{{ $v := .Site.Params }}
{{ range (split (.Get 0) ".") }}{{ $v = index $v (.) }}{{ end }}
{{ $v }}
content/_index.md
We are in mode {{< param "mode" >}}.
In case of turbulence, [reach the support](mailto:{{< param "support.mailing" >}}) for help.
After finding this link http://wtforms.simplecodes.com/docs/1.0.2/specific_problems.html#dynamic-form-composition I am trying to add fields to my Form. I am using Google App Engine and Jinja2.
This is the code I'm using.
def build_form(form_json):
class DynamicForm(wtforms.Form): pass
d = DynamicForm
name = "name"
setattr(d, name, TextField(name.title()))
return d
I send this to my jinja template. Within the template, I have this line:
<div>{{ new_form.name.label }}: {{ new_form.name }}</div>
Only the ':' shows up on the page itself.
When I look at the HTML source, I see this:
<div>: <UnboundField(TextField, ('Name',), {})></div>
Thanks for any insight.
You haven't instantiated the form, as shown in the code snippet you link to. d is the class, not the instance of it.
form = d()
or if it's a POST:
form = d(request.POST)