Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resources.Get throwing error with argument from shortcode parameter #8896

Closed
danisztls opened this issue Aug 16, 2021 · 9 comments
Closed

resources.Get throwing error with argument from shortcode parameter #8896

danisztls opened this issue Aug 16, 2021 · 9 comments

Comments

@danisztls
Copy link

danisztls commented Aug 16, 2021

Environment

hugo v0.87.0+extended linux/amd64 BuildDate=unknown

Issue

I don't know if this is a bug or just a leaky abstraction but inside a shortcode...

...this work as expected:

{{ $src := "image.jpg" }} 
{{ $image := resources.Get $src }}
<img src="{{ $image.RelPermalink }}">

while this doesn't:

{{ $src := .Get "src" }} 
{{ $image := resources.Get $src }}
<img src="{{ $image.RelPermalink }}">

throwing this error:

Error: Error building site: "/site/content/my-page.md:56:1": failed to render shortcode "image": failed to process shortcode: "/site/themes/my-theme/layouts/shortcodes/image.html:8:18": execute of template failed: template: shortcodes/image.html:8:18: executing "shortcodes/image.html" at <$image.RelPermalink>: nil pointer evaluating resource.Resource.RelPermalink

@danisztls danisztls changed the title resources.Get throwing resources.Get throwing error with argument from shortcode parameter Aug 16, 2021
@danisztls
Copy link
Author

Is this related to #7960?

@jmooring
Copy link
Member

How are you calling the shortcode?

@bep
Copy link
Member

bep commented Aug 16, 2021

Curious, what do you mean by leaky abstraction in this particular context?

That said, resources.Get is the exact same function in both scenarios.

@danisztls
Copy link
Author

@jmooring I'm not using page bundles.

The shortcode is called by the following on content/section/page.md

{{< image src="/img/subdir/image.jpeg" alt="Description" width="640" height="400">}}

Note: I moved the img dir to assets/.

Note 2: Currently I'm using it without problems with src="{{ .Get "src" }}" and images under static/.

@jmooring
Copy link
Member

In the future, please use the forum (https://discourse.gohugo.io) for questions and troubleshooting. We prefer to use GitHub for verified bugs and vetted enhancements. Thanks.

@danisztls
Copy link
Author

Curious, what do you mean by leaky abstraction in this particular context?

Because in my limited high level (superficial) undestanding the method resources.Get can be used like this. But maybe there are limitations for it that are not clear to anyone reading the documentation or at least for me.

That said, resources.Get is the exact same function in both scenarios.

It is but the later does not work.

@danisztls
Copy link
Author

@jmooring Thanks and in the future I will to that. But as far as I know this is not invalid and not solved. Why it is invalid?

@danisztls
Copy link
Author

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants