Jump to content

double or single, mix php html and css classes


bwakad
 Share

Recommended Posts

I now started to use normal html and use the normal php inside:

<img id="photo" src="<?php echo $child->image->getThumb('thumbnail');?>" />

this saves me from mistakes.

Because using either double or single qoutes, with more and longer lines where you would have 2 or maybe 3 parts of php AND maybe some classes for CSS it get's confusing.

I used to do $out = ."html code {php code} etc. and on the next line about the same. Eventually making echo $out;

I believe they call it something like concacating?

Then I read on internet single qoutes are faster because double qoutes need to be readed all the way before output takes place.

But again, the qoutes get's me confused when combining everything. It's also better to use $out = instead of $out .=

So what is the way you all doing it without errors - what is the better way?

Link to comment
Share on other sites

bwakad, I don't want to sound rude but how do you think this kind of questions are actually even related to ProcessWire? I know this is off topic section but still.. I suggest you buy yourself some PHP book for beginners and get the basics right - it helps you a lot with PW! http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dstripbooks&field-keywords=php

Edited by Roope
Link to comment
Share on other sites

Oh, php and processwire are rather intimately connected, I would say.

I am certainly not an expert, but the way I work is that where I am putting together my PW output within a function, then I will work much as you describe

$out = "";
$out .="<h1 class='myclass'>{$page->title}</h1>";

echo $out;

Those functions frequently sit in an included file somewhere.

When I write into a template, however, then I will often just break into php mid markup as you have done.

My useless rule of thumb tends to be "however I do it, make sure it is really, really obvious so that when I come back to it next week, I can work out what I was up to!"

But then, only I have to read my code. If I was working with someone else, I should probably be more regimented.

Link to comment
Share on other sites

Oh, php and processwire are rather intimately connected, I would say.

You're right, I edited my answer. Dealing with ProcessWire has taught me LOT from PHP but starting with PW can be real struggle without any basic knowledge of the language. It's really hard to build a house if you don't know how to hold the hammer  ^_^

Link to comment
Share on other sites

You're right, I edited my answer. Dealing with ProcessWire has taught me LOT from PHP but starting with PW can be real struggle without any basic knowledge of the language. 

I am working on that. Ummm ...  slowly.

Link to comment
Share on other sites

Looks like I am old fashion, I often think "was not PHP invented as such?" : <ul class="inline"><li><?php echo "something funny";?></li><ul>

When I would have used single qoutes or the way Joss's example it get's complicated.

btw, I see a lot of people on this forum use Hanna's code, but is it not just something like wordpress has?

Link to comment
Share on other sites

I am working on that. Ummm ...  slowly.

I hear you - your sig is my thoughts exactly. But we're getting there and PW makes learning PHP so damn fun that we can just smile and enjoy the ride!

  • Like 1
Link to comment
Share on other sites

I love the ProcessWire road with the by-product of learning PHP. ProcessWire makes me eager to learn.

And for the question: I don't like HTML in my template, I like php strings of HTML better. At the end it just makes it more readable. 

Mostly <?php is only used ones at the top of the file and thats it.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

I don't like HTML in my template, I like php strings of HTML better. At the end it just makes it more readable. 

Mostly <?php is only used ones at the top of the file and thats it.

What do you use to write code in?

I am using Notepad++, which gives very useful readable syntax highlighting, and tag/bracket pair matching, but does nothing to help make php strings of HTML more readable.

Any suggestions?

Link to comment
Share on other sites

I use Sublime mainly, but also use Np++ sometimes. PHP strings of HTML are highlighted just fine. Better if you concatenate variables within the strings (if any) rather than use curly braces..i.e.

Rather than....

"My string is about {$page->title} and other stuff"; 

use this..

"My string is about" . $page->title . "and other stuff"; 
Link to comment
Share on other sites

But in sublime you can set whatever you want to certain highlighting - which is also readable.

I now use google profile because it's one of the more clear ones. Unless you use php strings...

  • Like 1
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...