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

Not easy/obvious how to check which type of Link has been chosen in templates #10

Open
ghost opened this issue Oct 29, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Oct 29, 2020

Is there a simpler way to check what type of Link has been chosen other than something like this?

{% if block.ctaButton.className == 'flipbox\\craft\\link\\types\\Entry' %}
@nateiler
Copy link
Contributor

At the moment, that would be the only way to uniquely identify by type.

There is also {% if block.ctaButton.displayName() == 'Entry' %} but that's not unique and also gets translated. Depending on your scenario it may be another route.


I'm happy to introduce another mechanism that's a little more user friendly; I just need to keep third party link types in mind.

Off the top of my head I thought of introducing another attribute getShortType() or getType(). It wouldn't result in a unique reference, but you would know the link types installed and could handle appropriately. By default, this would produce the last part of a class name. Ex 'flipbox\craft\link\types\Entry' => 'Entry'.

To elaborate on the non-unique short type reference; someone could create their own link type with the class: your\namespace\Url which would result in two 'Url' short types (the other would come from 'flipbox\craft\link\types\Url'). Again something the developer would know and can account for; a rare scenario I assume.

Thoughts?

@ghost
Copy link
Author

ghost commented Oct 29, 2020

Hi Nate,

Thanks for your response! I definitely understand your point about the non-unique short type references.

For my purposes, your proposed solution would work. I was more or less looking for something like that when I gave up and used the long form check.

Whatever you feel is best works for me. I've solved my problem with the solution in my initial post, but I bet it would save others some time if the type checking were simpler and more obvious.

Thanks again!

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

1 participant