# Shortcode "Container with Title" & if parm exists Help

**URL:** https://discourse.gohugo.io/t/shortcode-container-with-title-if-parm-exists-help/25108
**Category:** support
**Created:** [April 28, 2020, 8:54pm UTC](https://discourse.gohugo.io/t/shortcode-container-with-title-if-parm-exists-help/25108 "2020-04-28T20:54:44Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![scottrlarson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/scottrlarson/32/4800_2.png) [@scottrlarson](https://discourse.gohugo.io/u/scottrlarson)
#### Post date: [April 28, 2020, 8:54pm UTC](https://discourse.gohugo.io/t/shortcode-container-with-title-if-parm-exists-help/25108/1 "2020-04-28T20:54:44Z")

</div>

I am trying to make a shortcode that wraps text into a div container that has style appled to a title heading and the paragraph text.

The goal here is that I want to check for a parameter “url” and if it exists then style the heading code with link markup. I have no idea how to use shortcode statements but below is the code. Maybe someone can point out where I going wrong. The shortcode is not rendering at all so I must be missing something:

shortcode example:

```
{{% alert title="This is a container header" url="/path/" %}}
This is the container text
{{% /alert %))

```

alert.html:

```
 <div class="alert-container">
  <h4>
    {{.Get "title"}}
    {{ if isset .Params "url" }}
    {{ with .Get "url" }}<a href="{{.}}">{{.Get "title"}}{{ end }}</a>
  </h4>
  {{ .Inner }}
</div>
```

---

<div class="post-metadata">

### Author: ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)
#### Post date: [April 29, 2020, 12:38am UTC](https://discourse.gohugo.io/t/shortcode-container-with-title-if-parm-exists-help/25108/2 "2020-04-29T00:38:42Z")

</div>

You are missing a closing `{{ end }}` for the `if` block.

`if isset .Params "url"` and `with .Get "url"` both do similar things, which is to check whether a “url” parameter is passed through.

Try this instead (untested):

```auto
{{ .Get "title" }}
{{ if isset .Params "url" }}
  <a href="{{ .Get "url" }}">{{ .Get "title" }}</a>
{{ end }}

```

You can read more about shortcode templates here: [https://gohugo.io/templates/shortcode-templates/](https://gohugo.io/templates/shortcode-templates/)

And general templating here: [https://gohugo.io/templates/introduction/](https://gohugo.io/templates/introduction/)

---

<div class="post-metadata">

### Author: ![scottrlarson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/scottrlarson/32/4800_2.png) [@scottrlarson](https://discourse.gohugo.io/u/scottrlarson)
#### Post date: [April 29, 2020, 12:55am UTC](https://discourse.gohugo.io/t/shortcode-container-with-title-if-parm-exists-help/25108/3 "2020-04-29T00:55:28Z")

</div>

Ok you got me on the right track. that worked but it duplicated the title. The below code works for me:

```
<div class="alert-container">
  <h4> {{ if isset .Params "url" }}
    <a href="{{ .Get "url" }}">{{.Get "title"}}</a>
    {{else}}
    {{.Get "title"}}
    {{ end }}
  </h4>
  {{ .Inner }}
</div>
```

---

<div class="post-metadata">

### Author: ![scottrlarson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/scottrlarson/32/4800_2.png) [@scottrlarson](https://discourse.gohugo.io/u/scottrlarson)
#### Post date: [April 29, 2020, 3:40am UTC](https://discourse.gohugo.io/t/shortcode-container-with-title-if-parm-exists-help/25108/4 "2020-04-29T03:40:45Z")

</div>

Is there a way to check for both params “title” and “url” and if they both dont exist only print the {{ .Inner }} part.?

---

<div class="post-metadata">

### Author: ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)
#### Post date: [April 29, 2020, 3:52am UTC](https://discourse.gohugo.io/t/shortcode-container-with-title-if-parm-exists-help/25108/5 "2020-04-29T03:52:21Z")

</div>

Please read the the templates intro in the docs, especially the conditionals section: [https://gohugo.io/templates/introduction/#conditionals](https://gohugo.io/templates/introduction/#conditionals)

```auto
{{ if and (isset .Params "url") (isset .Params "title" ) }} <-- both set
  <a href="{{ .Get "url" }}">{{.Get "title"}}</a>
{{ else if (isset .Params "title" ) }} <-- only title set
  {{.Get "title"}}
{{ else }} <-- neither set
  {{ .Inner }}
{{ end }}

```

---

<div class="post-metadata">

### Author: ![scottrlarson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/scottrlarson/32/4800_2.png) [@scottrlarson](https://discourse.gohugo.io/u/scottrlarson)
#### Post date: [April 29, 2020, 10:44pm UTC](https://discourse.gohugo.io/t/shortcode-container-with-title-if-parm-exists-help/25108/6 "2020-04-29T22:44:18Z")

</div>

Will do. Thank you for pointing me in the right direction.

---

<div class="post-metadata">

### Author: ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)
#### Post date: [May 1, 2020, 10:56pm UTC](https://discourse.gohugo.io/t/shortcode-container-with-title-if-parm-exists-help/25108/7 "2020-05-01T22:56:53Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
