使用 EL 作为布局宏表达式的参数
Using EL as parameters for layout-macro expressions
尝试使用 EL 生成将变量作为布局宏输入的 a -> param -> expression/literal。但它一直给我编译错误或输入我的 EL 的文字。
目前有办法做到这一点吗?
layout-macro-def (game-details) {
params {
param (game) {
type (Game)
min (Required) max (One)
}
}
// [...]
for-each (game.external_games) {
as (item) {
switch (item.category) {
case (1) { // Steam
layout-macro (UriButton) {
param (url) { // <<----- Expression for this is giving me issue
expression ("https://store.steampowered.com/app/#{value(item.uri)}")
}
param (image) {
literal (https://cdn.discordapp.com/attachments/354331388142419988/567499944391344158/unknown.png)
}
param (name) {
literal ("Steam")
}
}
}
// [...]
编辑添加的上下文
布局宏
layout-macro-def (UriButton) {
params {
param (url) {
type (URL)
min (Required)
}
param (image) {
type (URL)
min (Required) max (One)
}
param (name) {
type (Name)
min (Required) max (One)
}
}
content {
cell-card {
on-click {
intent {
goal: UriRedirect
value: UriRedirect {
url {$expr(url)} // <--- Ultimate goal URL with URI appended to the end
}
}
}
slot1 {
image {
shape (Square)
url ("#{value(image)}")
}
}
slot2 {
content {
primary ("#{value(name)}")
}
}
}
}
}
事实证明,您将模板放在需要表达式的位置。模板包含表达式(在 #{} 内)但它们本身不是表达式。
使用如下模板。
layout-macro (UriButton) {
param (url) {
dialog-template {
template ("https://store.steampowered.com/app/#{value(item.uri)}")
}
}
尝试使用 EL 生成将变量作为布局宏输入的 a -> param -> expression/literal。但它一直给我编译错误或输入我的 EL 的文字。
目前有办法做到这一点吗?
layout-macro-def (game-details) {
params {
param (game) {
type (Game)
min (Required) max (One)
}
}
// [...]
for-each (game.external_games) {
as (item) {
switch (item.category) {
case (1) { // Steam
layout-macro (UriButton) {
param (url) { // <<----- Expression for this is giving me issue
expression ("https://store.steampowered.com/app/#{value(item.uri)}")
}
param (image) {
literal (https://cdn.discordapp.com/attachments/354331388142419988/567499944391344158/unknown.png)
}
param (name) {
literal ("Steam")
}
}
}
// [...]
编辑添加的上下文
布局宏
layout-macro-def (UriButton) {
params {
param (url) {
type (URL)
min (Required)
}
param (image) {
type (URL)
min (Required) max (One)
}
param (name) {
type (Name)
min (Required) max (One)
}
}
content {
cell-card {
on-click {
intent {
goal: UriRedirect
value: UriRedirect {
url {$expr(url)} // <--- Ultimate goal URL with URI appended to the end
}
}
}
slot1 {
image {
shape (Square)
url ("#{value(image)}")
}
}
slot2 {
content {
primary ("#{value(name)}")
}
}
}
}
}
事实证明,您将模板放在需要表达式的位置。模板包含表达式(在 #{} 内)但它们本身不是表达式。
使用如下模板。
layout-macro (UriButton) {
param (url) {
dialog-template {
template ("https://store.steampowered.com/app/#{value(item.uri)}")
}
}