I am working in a webpage where client scripting is not allowed. This webpage uses a very huge verbose tag in the shape of:
<embed src="X" flashvars="Y"/>
It is part of a tmeplate, so it will be used in lots of pages, so I have to change the hardcoded params in an easy way for all them.
I am wondering if there is a way to do something like this in HTML:
<var name="X" content="foo">
<var name="Y" content ="bar">
<embed src="<X/>" flashvars="<Y/>"/>
So the last part would not be changed in template and all child inherited pages
Thank you!
HTML alone cannot do this. HTML is a markup language, not a programming language. It doesn't even have variables.
You need server-side coding for this. PHP is the most popular, though there are numerous others available. Then you could do this:
<?php
$x = 'something';
$y = 'somethingElse';
?>
<embed src="<?php echo $x; ?>" flashvars="<?php echo $y; ?>">
No it is not possible. HTML is static.
If you cannot use a clientside script have you thought about a serverside script?
Not through HTML directly.
You could use JavaScript to inject the values, but HTML itself does not store variables.
Related
I wonder how to make shortcut URL in html and css (if it is possible)
I mean this:
HTML URL1
CSS #URL1 { URL('nextpage.html');}
Is this somehow possible?
Thank you for your answers.
So it can't work like this?
var url1 = "http://www.google.com";
Google
Is there any option how to do it?
To give you the short answer, no, you can't achieve this only by using CSS and HTML.
Cascading Style Sheets (CSS) is a style sheet language used for describing the look and formatting of a document written in a markup language. While most often used to change the style of web pages and user interfaces written in HTML and XHTML, the language can be applied to any kind of XML document, including plain XML, SVG and XUL. (...read more)
Also, here is an introduction to what CSS is and how to use it.
I recommend you also take a look at HTML Links.
To not be all negative, I will give you some solutions, you could use .attr and do it like this :
SCRIPT
$('#firstlink').attr("href", "http://google.com")
HTML
This will take you to google
...or you could do it like this:
SCRIPT
var url = document.getElementById("firstlink")
url.setAttribute("href", "http://google.com")
HTML
This will take you to google
It can't be possible. As css is for only styling the html.
Yes you can target particular url to style it.
Check out this page for further detail.
Or you can do it with php.
<?php
$url = 'example.com' ;
?>
<a href="<?php echo $url; ?>" >
click here
</a>
So I'm using this:
<div id="record-<?php echo $idi ?>" class="record">
....bunch of stuff...
</div>
and this works for my JS function and is returning the PHP value. Whenever I do this though my dev software (I'm using Dreamweaver) can't determine (see and thus highlight) the end of the div tag. Is this because the dev software sucks or cause my syntax sucks, or none of the above?
thanks in advance
your syntax is fine. it's just dw. although you could shorten your php to <?=$idi?>
I'm using the multiEdit plugin to create some content regions on a template.
One of those region is for some photos that are going to be using jQuery cycle to rotate through the images.
But, as usual, Wordpress (or the editor rather) is wrapping all of the images in a <p> tag.
I've used the functions hack from CSS-Tricks to remove the <p> tags from the content:
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
But, from what I can tell, it only looks for the_content and not for anything else.
Multiedit uses this: <?php multieditDisplay('name_of_region'); ?> to display the content block in the template.
So, I tried to change the function to this:
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('multieditDisplay', 'filter_ptags_on_images');
But no such luck.
So, I'm not so sure if I'm missing something or just going about it the wrong way.
Ok, well I found a workaround.
I did a write up about it here:
http://ultraloveninja.roon.io/filtering-paragraph-tags-with-the-wordpress-multiedit-plugin
Instead of placing multiEdit fields in your template like this example
<?php multieditDisplay('Top'); ?>
You could prevent the auto print by passing true as the second parameter like this
<?php echo multieditDisplay('Top', true); ?>
So if you want to strip ALL tags from the output, then try this
<?php echo strip_tags(multieditDisplay('Top', true)); ?>
If you want to include certain tags then provide a list of tags to include and pass it as a parameter to strip_tags like this
<?php echo strip_tags(multieditDisplay('Top', true), '<p><a>'); ?>
First a bit of background information. I create HTML emails at my work place and the whole process is very tedious. It goes a little little like this...
Code markup for HTML using tables and some CSS
Parse HTML and CSS using Premailer so all CSS is inline
Test HTML works in all email clients
Create a copy of the inline version of HTML and start adding in proprietary variables to email tool used for sending emails, ie <%=constant.first_name%>, <%=unsubscribe_link%>
Test in email client to see if it works and client is happy. If not repeat steps 1 through 5 again.
So as you can see it gets really tedious after a while.
What I would like to do is create a command line script similar to Premailer which allows me to parse a HTML file with variables stored in it without destroying the example text already in the HTML. That way when you are previewing the HTML it all looks dandy.
For example...
Store the first name function as a variable for own use.
$first_name = "<%=constant.first_name%>
Then tell the parser what word(s) to replace with the appropriate variable.
<p>My name is <!-- $first_name -->Gavin<!-- /$first_name --></p>
So that the final output looks something like:
<p>My name is <%=constat.first_name%></p>
Would such a thing be possible? Is there a better syntax I could, a custom tag like <first_name>Gavin</first_name>, if the browser can handle it.
Any advice is helpful. :)
I've seen this done before using a syntax like:
{assign_variable:first_name="Jesse"}
Then, you could use it like:
{first_name}
The way you'd parse this (provided you're using PHP) would be something like:
<?php
// Our Template Code
$strHTML = <<<EOT
{assign_variable:first_name="Jesse"}
{assign_variable:last_name="Bunch"}
Hello, {first_name}!
EOT;
// Get all the variables
$arrMatches = array();
preg_match_all('/\{assign\_variable\:([a-zA-Z\_\-]*)\=\"([a-zA-Z0-9]+)\"\}/', $strHTML, $arrMatches);
// Remove the assign_variable tags
$strHTML = preg_replace('/\{assign\_variable\:([a-zA-Z\_\-]*)\=\"([a-zA-Z0-9]+)\"\}/', '', $strHTML);
// Combine them into key/values
$arrVariables = array_combine($arrMatches[1], $arrMatches[2]);
foreach($arrVariables as $key=>$value) {
// Replace the variable occurrences
$strHTML = str_replace('{' . $key . '}', $value, $strHTML);
}
// Send the parsed template
echo $strHTML;
Which outputs:
Hello, Jesse!
Note, this is a very basic example. Here are some improvements to make on this code before using it in production:
Edit the regex to allow the right characters.
Maybe implement a better replacement method than a loop
Check for parse errors
Benchmark performance
All in all, I think you get the idea. Hope this points you in the right direction.
I have a similar situation
I have created a "format template" like this:
<?php // section1 $var1/$var2 ?>
<head>
<title>$var1</title>
<meta name="description" content="$var2">
</head>
<?php // section2 $var1/$var2 ?>
<body>
hello: <p>$var1</p>
news for you: <p>$var2</p>
</body>
it is valid php code and valid html code, so you can edit it with dreamwaver or similar, and you can host it also.
then a php script replaces all ocurrences of vars in all sections.
I do a lot of slicing in Photoshop, and it's tedious to manually write an <img /> tag for each of them -- writing in the filename, checking height and width, writing the alt tags, etc.
I can use Photoshop to generate the HTML, but they usually muck it up by not producing XHTML, or by wrapping it in tables, and so forth. I'm trying to make my life easier than that.
So I'm wondering if anyone uses a script that automatically generates img tags based on the directory? Or if some IDE that I don't know about does this? I just want it to generate a bunch of tags like so:
<img src="{filename}" alt="" width="{width}" height="{height}" />
First I want to commend you on having width and height information in an image. It's very good that you do this, everyone should do this. You could use any scripting language such as Python or PHP to do this with an image library such as imagemagick or gd. Without knowing what language or tools you're using to run your site I can't really provide an example.
In Python, using a template system you might do something like this:
<div>
<% addImg("/images/myImage.png") %>
</div>
Which would generate the right image tag:
<div>
<img src="/images/myImage.png" alt="MyImage" width="200" height="100" />
</div>
Somewhere in your python you define:
def addImg(imgPath):
#do image processing here
If Photoshop does a decent job of this, it may be easiest to just process the output from there, using a regex or something to fix the problems in it. This would probably be simpler than trying to reimplement that functionality from scratch.
If you can post a sample of Photoshop's HTML output, I can supply a regex search/replace that'd convert it to what you're looking for.
Made php script:
<?php
$images = scandir('images');
$txt = '';
$tmpl = '<img id="{{id}}" src="images/{{name}}">';
foreach($images as $image) {
$tag = $tmpl;
$tag = str_replace('{{id}}', explode('.', $image)[0], $tag);
$tag = str_replace('{{name}}', $image, $tag);
$txt .= $tag . "\n";
}
file_put_contents('tags.txt', $txt);
Create a php file and run it:
php script.php
Php script has to be in same directory as images folder.
You will get your image tas in tags.txt file.