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

Can we provide the model relations data to the template? #29

Open
danielsuguimoto opened this issue Feb 15, 2021 · 1 comment
Open

Can we provide the model relations data to the template? #29

danielsuguimoto opened this issue Feb 15, 2021 · 1 comment

Comments

@danielsuguimoto
Copy link
Contributor

Can we use placeholders with relations, eg model1.model2.field?

@daniel-werner
Copy link
Collaborator

daniel-werner commented Feb 23, 2021

Hi @danielsuguimoto,

This is a bit tricky, and there is no complete support for it currently, but I can suggest some workarounds:

  1. The simplest would be to add the related model data as separate template data
        $documentTemplate->addTemplateData($model1, 'model1');
        $documentTemplate->addTemplateData($model2, 'model2');
  1. or, for a first level relation we can add the relation to the getTemplateFields method of the model1:
    protected function getTemplateFields()
    {
        return [
            'any_other_field',
            'model2'
        ];
    }

and use it in the template like {{model1.model2.field}}. It should work as expected. Unfortunately this workaround is not universal, deeper level relations won't work. Also it would show up in the ckeditor dropdown as model1.model2 without the actual fields from the model2.

Obviously these are not ideal solutions, and it makes sense to add support for the model relations in general. (including the admin part and the ckeditor).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants