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

Add support for EQUALS macro to allow for easy variable substitution #22160

Closed
harshvcs opened this issue May 6, 2019 · 2 comments
Closed

Add support for EQUALS macro to allow for easy variable substitution #22160

harshvcs opened this issue May 6, 2019 · 2 comments

Comments

@harshvcs
Copy link

harshvcs commented May 6, 2019

Add EQUALS macro to allow for easier string output mapping

There is currently no support from available macros to map variable values that might be required by a vendor in their amp-analytics vendor file. To achieve multiple output string mapping, most of the vendors will need something that checks for equality - say a new EQUALS macro (that returns a===b) along with the existing $IF macro.

Assuming $EQUALS is added, then a required mapping like "A" -> 1, "B" -> 2, "C" -> 3 can be solved using:

$IF($EQUALS(${variable}, A), 1, $IF($EQUALS(${variable}, B), 2, 3));

Alternative

An alternative that uses the $REPLACE macro is shared here, but in general, it is cumbersome to implement and understand.

Additional context

This is originally discussed with @zhouyx in #18034

@zhouyx
Copy link
Contributor

zhouyx commented May 20, 2019

to @jonathantyng-amp could you take this? Thank you

@zhouyx zhouyx assigned jonathantyng-amp and unassigned zhouyx May 20, 2019
zhouyx pushed a commit that referenced this issue Jun 18, 2019
* add new EQUALS macro

* change IF behaviour

* remove console log

* fix return type

* change stringToBool to helper
@zhouyx
Copy link
Contributor

zhouyx commented Jun 18, 2019

Closed by #22404

@zhouyx zhouyx closed this as completed Jun 18, 2019
thekorn pushed a commit to edelight/amphtml that referenced this issue Sep 11, 2019
* add new EQUALS macro

* change IF behaviour

* remove console log

* fix return type

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

No branches or pull requests

4 participants