Ha, I didnāt know that, thanks!
this is the verbose url of course, while I would love to use the view, to make things simpler and easier to read in the templates. Like we can do in Custom header as described on Custom Header
would it be an accepted FR to support some of these builtin variables on Button-card too?
ok thanks, will give it a go. should I use templates on each property individually, like below, or is there a smart way of doing so in short-hand:
meaning the window.location is displayed alright, but I cant see the user.
Tbh, I am struggling with whatās written at the bottom here button-card/README.md at master Ā· custom-cards/button-card Ā· GitHub on the variables available inside the JS codeā¦ How do I use that? I didnāt find any example or documentation about user (or has for that matterā¦) must be missing the obvious, but in all my button configs, Iāve simply never encountered the need/issue
correct, sorry, didnt realize it was a link to the W3schoolā¦still, it doesnāt allow finding the view name only, or the Lovelace path, as defined in the view config:
title: Test
icon: mdi:test-tube
path: test
cards:
window.location.pathname coming closest, but still returning ā/lovelace/testā
so
wow, thatās a first for me, have to study whatās done there, and how to use the templates in that. let and āresā being the great unknowns to meā¦back to w3schools I fear
I tried a standard construction with if (window.location.pathname.split('lovelace/')[1] == 'home') but got stuck declaring the let that way.
Now I am stuck returning the resā¦with the double āreturnā in the template
Thatās the thing here. Youāve been here a LONG time. One basic element of all langauges (doesnāt matter the language) is object typing. If you take a beginner course in ANY language, you learn about this in the first 3 tutorials. Iāve been harping on you for years to take something with the amount of developing that you do and itās clear you still havenāt.
If you get Object object in js as your returned string, that means you have an OBJECT and not a STRING. I.E. you convert the object to a string with a simple google search āconvert window.location.pathname to stringā.
EDIT: And just to clarify, I didnāt know how to do this and simply googled that and showed you the first result that I found.
think there is some misunderstanding goin onā¦ what did you think I was asking? because thereās no problem getting the path(name) to the button frontend.
Yes I understand thatā¦ that is because depending on the state of the pathname, I either want to trigger the entity_id, or navigate to another view. These 2 different actions need to different dictionaries. Or so I thoughtā¦
youāre returning a string here but it should be the value of the variable, not the string. Also youāre missing the service_data. Iāve cleaned up your code a bit.
[[[
let res; // let is same as var. res is just a variable name.
if (window.location.pathname.split('lovelace/')[1] == 'home') {
res = {
action: "navigate",
navigation_path: "developer"
};
} else {
res = {
action: "call-service",
service: "automation.trigger",
service_data: {
entity_id: entity.entity_id,
}
};
}
return res;
]]]
EDIT: Actually, it might not work (just re-looking at the button-card code right now and how Iāve handled it But you can give it a try)