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?>
Related
In VS Code I am having trouble in formatting HTML.
For example, I write a list of tags inline and I press Shift+Alt+F and nothing happens.
I noticed this:
If I write:
<div><span><p></p></span></div>
nothing happens when I do the auto format.
If I write:
<div><div><div></div></div></div>
then it becomes:
<div>
<div>
<div></div>
</div>
</div>
hope this will help you to help me...
We had the same problem in my dev team. Please check or try the following things:
Are the keyboard bindings correct?
Is selected code language HTML?
Have you restarted VS code?
Begin a small piece of the formatting and then try again (for some reason it
thinks its already correct.
There are a certain list of tags that are ignored when auto formatting - these are defined in the setings.json file under
html.format.unformatted":
So go to settings (Command-Comma on a mac) and search for that setting and remove the tags you do want formatting.
The bad news is that it still doesn't format how I think it should - i.e. the isn't indented inside the but it at least puts it on a new line for you!
This is a VS code bug. I installed the 1.17 and it worked very well https://code.visualstudio.com/updates/v1_17
I am learning html, css and content management by building my own personal site, but I have very little experience in any of these areas. One thing that has bothered me is the amount I have to repeat a segment of "html code". For example, on my site I may have a block that looks like:
<div class="talk">
<a href="link">
title
<div class="info">
subtext
</div>
</a>
</div>
where link, title and subtext are the only elements that change. As a programmer, this looks like a function with three arguments: talk(link, title, subtext) and I would implement this by keeping a separate text file or database with all the entries and a program to "compile" the data and the HTML formatting into a final product. In fact, this is what I do now with a simple python script and BeautifulSoup. I have a feeling though, that there are tools out there for exactly this sort of thing, but there are so many options and systems I not even sure what I'm looking for exactly (Grunt, bower, Ruby on Rails, SASS, HMAL, handlebars, ...). This is not a request for recommendations, an acceptable answer could involve any framework, but I prefer simplicity over power.
What is canonical/standard way to do this? What is a minimal working example using my code block above?
Since you asked for a live example, here is one in PHP:
news_print.php
function output_some_news ($link, $title, $subtext)
{
echo
"<div class='talk'>
<a href='$link'>
$title
<div class='info'>
$subtext
</div>
</a>
</div>";
}
// this is just for show. Usually the data come from a database or data file
$topics = array (
array ("http://celebslife.com", "Breaking news", "Justin Bieber just grew a second neuron"),
array ("http://nerds.org" , "New CSS draft available", "We won't be forced to use idiotic lists to implement menus in a foreseeable future"));
function output_news ($topics)
{
foreach ($topics as $topic)
{
output_some_news ($topic[0], $topic[1], $topic[2]);
}
}
And from within your HTML page:
news.php
<?php include 'news_print.php'; ?>
<div class='news'>
<?php output_news($topics); ?>
</div>
As for using PHP as a preprocessor, it is pretty straightforward:
C:\dev\php\news> php news.php > news.html
will produce pure HTML from your PHP script.
The PHP engine will be invoked from the command line instead of a web server, and its output will be stored in a file instead of being sent back to a browser, that's all.
Of course you will have some differences. For instance, all the web-specific informations like caller URL, cookies, etc. will not be available if you use PHP offline. On the other hand, you will be able to use command line arguments and environment variables.
I am trying to display chunks of HTML from a DB, and sometimes it is a portion of the entire HTML page, so may be invalid, since I may be returning the first 500 chars. I may get:
<h1>test</h1><div id="
At present this corrupts the containing page.
Can this be wrapped up in someway, by some tags, such that it does not corrupt the containing HTML.
My initial idea was something like:
<div>
<h1>test</h1><div id="
</div>
However this does not work.
Also it would be ideal if any valid HTML did work as expected, so the above would look like:
Test
It may not be possible, but I thought I would ask.
I am not aware of what Server Side/Client Side language you are using, but I assume you are using PHP, you need to use strip_tags() to strip all the HTML text first, and than try echoing it..
<p class="static_wrapper">
<?php echo substr(strip_tags($fetched_row['column_name']),0,100).'...'; ?>
</p>
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.
Does HTML support a behavior of text rendering where multiple lines will be avoided with an automatic placement of "..." ? Sorry, I just cannot find the style/tag associated with this behavior, if it exists!
No, there is nothing built in.
You need to either do it yourself serverside, or write some JavaScript that will count lines and replace the rest of the line with an ellipsis (...).
There is a text-overflow-mode defined in the CSS3 spec that will do this, but as a working draft it is not final and will not necessarily work on current browsers.
The property you're looking for is the CSS text-overflow: ellipses. Unfortunately it does not work in Firefox. Here is a resource on it:
http://www.css3.info/preview/text-overflow/
You can kind of hack it in Firefox, with e.g.
http://www.jide.fr/english/emulate-text-overflowellipsis-in-firefox-with-css
But the only real cross-browser solution would be a JavaScript one, like this maybe, or perhaps one of the ones in the comments on this page:
http://ajaxian.com/archives/ellipsis-or-%E2%80%9Ctruncate-with-dots%E2%80%9D-via-javascript
Short answer: No.
Longer answer: This is possible if you're using a programming backend (e.g. PHP) that outputs HTML to the front end. You could do something like
<?php
if(str_len($yourText) > 100) {
echo substr($yourText, 0, 100) . "...";
}
?>