Nested shortcode issue

Hi,

I have a shortcode that I’m trying to pass in the value from the relref shortcode for a link.

My markdown looks like this:

{{% media src="/img/g78363.png" width="80px" heading="My Heading" link="{{< relref "service.md" >}}" %}}
  This is a description of the service.
{{% /media %}}

and my custom meadia.html shortcode looks like this:

<div class="media">
  <div class="media-left">
    {{ with .Get "link"}}<a href="{{.}}">{{ end }}
      <img class="media-object" src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}
      {{ end }}"{{ end }} 
      {{ with .Get "width"}} width="{{.}}"{{ end }} />
    {{ with .Get "link"}}</a>{{ end }}
  </div>
  <div class="media-body">
  	{{ with .Get "link"}}<a href="{{.}}">{{ end }}
    <h4 class="media-heading"><strong>{{ .Get "heading" }}</strong></h4>
    {{ with .Get "link"}}</a>{{ end }}
    {{ .Inner }} 
  </div>
</div>

The error that I’m getting

Change detected, rebuilding site
2016-01-29 16:54 -0500
ERROR: 2016/01/29 suppression:43: got positional parameter ‘service’. Cannot mix named and positional parameters
0 of 1 draft rendered
0 future content
34 pages created
21 paginator pages created
0 categories created
15 tags created
in 198 ms

It appears from the documentation, as well as other posts on the forums that nested shortcodes are supported.

Any guidance as to what I am doing wrong? Thanks!

The thing you are trying to do isn’t a nested shortcode. You try to pass a shortcode as a parameter. That isn’t supported. Only string arguments.

This is a nested construct:

{{% media src="/img/g78363.png" width="80px" heading="My Heading"  >}}" %}}
  This is a description of the service.
 {{< relref "service.md" >}}
{{% /media %}}
1 Like

Thanks @bep.

Can a shortcode HTML file contain a call reference to another shortcode?

So in my example, could the media.html file contain within it’s HTML a call to
{{< relref "service.md" >}} ?

Yes, as in my example. Pull the service.md in as a string argument, and you should have what you want, me thinks.

@bep sorry if I’m being dense here, but how would I go about referencing the string argument in this case.

When I pass:

{{% media src="/img/g78363.png" width="80px" heading="My Heading"  >}}" %}}
  This is a description of the service.
 {{< relref "service.md" >}}
{{% /media %}}

My media shortcode processes the “This is a description of the service”, along with the relative path “/services/” as text that is within the .Inner operator.

There something that I’m not clear on how to reference the data being passed in within the shortcode so I can use this data for the link address within the anchor tag.

The media shortcode …

<h1>{{ .Get "heading" }}</h1> ...
{{ .Get "service" | relref .Page }}

Thank you @bep. That certainly helps.

I am having one issue when I don’t pass in a “link” parameter to my media shortcode (since not everything will have a hyperlink).

In my current shortcode I’m using the following syntax:
{{ with .Get "link" | relref .Page}}<a href="{{.}}">{{ end }}

With the addition of the | relref .Page, when I don’t pass in a link I’m getting Error messages during the site build process:
ERROR: 2016/02/02 ref could not be found

Is there some other way that I should be writing this to prevent these error messages when a link is not being passed to the shortcode?