Jump to content

Zen-Coding


seventheyejosh

Recommended Posts

Ya it is really slick if you are sick of typing out all your ul's and li's or even your divs.

 

I use Komodo Edit on Snow Leopard, so I grabbed it for that, but our house designer got it for Aptana, and it works the same.

 

It has a couple of commands, but I just use (so far) the Expand Abbreviation, which I mapped to Ctrl+, and Wrap Abbreviation, which I mapped to Ctrl+Shift+,.

 

So anyway, the idea is you type a string of text, using css selectors, and hit your hotkey at the end of the line, and volia, html!

 

You can use any element, ul, div, head, etc

 

You can use # for id, . for class, * for iterations, and $ for the number of the current iterator

 

SO....

 


Type: div#mydiv

Hit hotkey at end of line

Result:

<div id="mydiv></div>

 


Type: ul#mynav>li*3

Hit hotkey at end of line

Result:

<ul id="mynav">
     <li></li>
     <li></li>
     <li></li>
</ul>

 


Type: ul#mynav>li.item-$*3

Hit hotkey at end of line

Result:

<ul id="mynav">
     <li class="item-1"></li>
     <li class="item-1"></li>
     <li class="item-1"></li>
</ul>

 


Type: html>head+body>div#wrapper>div#header+div#left+div#right+div#footer>ul.navigation>li.item-$*5>a

Hit hotkey at end of line

Result:

<html>
    <head></head>
    <body>
        <div id="wrapper">
            <div id="header"></div>
            <div id="left"></div>
            <div id="right"></div>
            <div id="footer">
                <ul class="navigation">
                    <li class="item-1"><a href=""></a></li>
                    <li class="item-2"><a href=""></a></li>
                    <li class="item-3"><a href=""></a></li>
                    <li class="item-4"><a href=""></a></li>
                    <li class="item-5"><a href=""></a></li>
                </ul>
            </div>
        </div>
    </body>
</html>

 

And the other thing you can do is wrap, using just *, with no amount to detect the items. Nice if you have a list of items.

 


Type:

Home
About Us
Contact
Shop
Forum

HIGHLIGHT ALL, Hit Wrap Abbreviation hotkey.

Type: ul#mynav>li.item$*

Hit Ok

Gives:

<ul id="mynav">
    <li class="item-1">Home</li>
    <li class="item-2">About Us</li>
    <li class="item-3">Contact</li>
    <li class="item-4">Shop</li>
    <li class="item-5">Forum</li>
</ul>

 

Pretty sick eh?

Link to comment
https://forums.phpfreaks.com/topic/199539-zen-coding/#findComment-1047468
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.