Skip to content

[5.x]: Can't render element cards in "Template" field layout element #16267

@Mosnar

Description

@Mosnar

What happened?

Description

We use a template field element to render where particular elements are referenced (e.g. show a list of blog posts referencing a particular product). To keep things stylistically homogenous, I used {% hook "cp.elements.element" %} to render a link to the elements. In Craft 5, this hook is deprecated and we're told to use the Cp::elementCardHtml() function; however, this function is not available in the site template mode, which is what's used for rendering these templates.

Here's the Twig code for the embedded template: https://gist.github.com/Mosnar/f8aebd38fc4548dc9249631401666fc9

Steps to reproduce

  1. In a field layout "Template" element, use {% hook "cp.elements.element" %} (or insert code from attached Gist)
  2. See deprecation warning logged

Expected behavior

Ideally, I'd like to be able to use elementCardHtml() in the Template field layout element without needing to write a custom plugin or module.

Craft CMS version

5.5.3

PHP version

8.2.26

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

Metadata

Metadata

Assignees

Labels

authoring ✍️features related to author experience

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions