Zen Coding for PHP

1,175 views
Skip to first unread message

TomDB

unread,
May 20, 2011, 5:06:45 AM5/20/11
to Zen Coding
I've heard about this Zen Coding quite often, I'm trying it out now
with Notepad++.

However, what I'm really longing for is something that would speed up
the default PHP coding. I often (very often) find myself writing PHP
like

if (is_array($arrayname)) {
foreach ($arrayname as $rowname) {

... do stuff here

}
}

It would be great if that could be expanded by a simple command like

foreach#arrayname>rowname

or whatever syntax you'd like ...

Is this possible with ZenCoding (or an other Notepad++ plugin, or even
in an other Windows editor ?)

Sergey Chikuyonok

unread,
May 20, 2011, 5:50:19 AM5/20/11
to zen-c...@googlegroups.com
The ultimate solution for your problem is to use good old snippets with placeholders, available in many modern editors (I’m using Eclipse, for example, and it works really fine).
But, if you still want to use Zen Coding for such cases, your snippet will look like this:

foreach: 'if (is_array($arrayname)) {\n\tforeach (${id} as ${class}) {\n\t\t|${child}\n\t}\n}''

Snippet call:
foreach#arrayname.rowname

___________________________________________
Сергей Чикуёнок
http://chikuyonok.ru
serg...@gmail.com

TomDB

unread,
May 20, 2011, 6:38:51 AM5/20/11
to Zen Coding

where could I need to put that line? In which file, which block ?



On May 20, 11:50 am, Sergey Chikuyonok <serge....@gmail.com> wrote:
> The ultimate solution for your problem is to use good old snippets with placeholders, available in many modern editors (I’m using Eclipse, for example, and it works really fine).
> But, if you still want to use Zen Coding for such cases, your snippet will look like this:
>
> foreach: 'if (is_array($arrayname)) {\n\tforeach (${id} as ${class}) {\n\t\t|${child}\n\t}\n}''
>
> Snippet call:
> foreach#arrayname.rowname
>
> ___________________________________________
> Сергей Чикуёнокhttp://chikuyonok.ru
> serge....@gmail.com

Sergey Chikuyonok

unread,
May 20, 2011, 6:40:07 AM5/20/11
to zen-c...@googlegroups.com
Read this tutorial:
http://www.smashingmagazine.com/2009/11/21/zen-coding-a-new-way-to-write-html-code/

___________________________________________
Сергей Чикуёнок
http://chikuyonok.ru
serg...@gmail.com

TomDB

unread,
May 20, 2011, 7:56:23 AM5/20/11
to Zen Coding
thanks, i'm beginning to understand :)

one (hopefully final) question: how can I define a snippet that should
output a $ ? I tried escaping it with a backslash in front, but still
it's replaced by the number ...

I'd like
foreach#myarray.myrow to be converted to foreach ($myarras as
$myrow) ... without having to specify the $ in the id / class...



On May 20, 12:40 pm, Sergey Chikuyonok <serge....@gmail.com> wrote:
> Read this tutorial:
>  http://www.smashingmagazine.com/2009/11/21/zen-coding-a-new-way-to-wr...

Sergey Chikuyonok

unread,
May 20, 2011, 7:58:10 AM5/20/11
to zen-c...@googlegroups.com
you should double-escape it, e.g. \\$

___________________________________________
Сергей Чикуёнок
http://chikuyonok.ru
serg...@gmail.com

TomDB

unread,
May 20, 2011, 9:39:22 AM5/20/11
to Zen Coding
yes, that works fine. One thing that keeps comming though is the fact
that the class always has an extra space before. Even when I have only

snippet definition:

'foreach': '${class}'

and I try

foreach#id.myclass

it's returned as
" myclass" (without the quotes of course)

where does that extra space come from? When I try the same with
div#id.myclass, it's nicely without a space...




On May 20, 1:58 pm, Sergey Chikuyonok <serge....@gmail.com> wrote:
> you should double-escape it, e.g. \\$
>
> ___________________________________________

Sergey Chikuyonok

unread,
May 20, 2011, 9:42:46 AM5/20/11
to zen-c...@googlegroups.com
This is pretty weird, it should place class name as is but replace all dots with spaces. I’ll take a look at the source code

___________________________________________
Сергей Чикуёнок
http://chikuyonok.ru
serg...@gmail.com

Reply all
Reply to author
Forward
0 new messages