I want to create a variable in html, and it's value is a link to a website. This is for a weekly email template and the link changes every week and the same link occurs several times in the template. So instead of going through and copy pasting a new link several times in the code, I want to just change the value of the variable so it just updates all the links in one go.
I'm a complete rookie at coding and any help is appreciated
I wish I could tell you this is easily done, but it isn't. HTML email is a whole different beast from an HTML website, as I had the pleasure of learning earlier this year. Please read up on this link before you actually write an HTML email.
Now that you see html email is much more of a hassle, you may realize that it won't be possible to use code that executes client side - it's just not safe and no one really allows it in email. If you are using php, then this is your easy solution. Decide on a good variable name, and define it. Then place that variable each time you want the link. PHP will work because it is executed server-side, so you won't have to worry about any PHP code reaching the client. Here is a super easy example that will output "Here is a link to likeplum: http://www.likeplum.com."
<?php $link = "http://www.likeplum.com";
echo "Here is a link to likeplum: $link";
Of course! You can place PHP anywhere in an html page. If you are new to coding in PHP, i recommend picking up a book or searching for a free online resource to learn how it works. As for creating a call so it just changes the link and the text separately, you can do something like this. Now, when you change link it will actually change the href property of the a tag, while when you change text it'll change what the link says.
$text = "Click here for likeplum.";
<a href="<?php echo $link ?>"><php echo $text ?></a>
This will give you a link to likeplum that says "Click here for likeplum."
Jun 20th, 2013
Did you know? You can earn $20 for every friend you invite to Studypool!