ScarLight
ScarLight

Reputation: 21

Zen coding in .php extension with Sublime Text 2

I'm used to doing zen coding in .html file and it works! But I cant figure out how to do the same when im in .php file, tried ctrl+alt+enter too but nothing happened. I'm working on a Joomla website so the theme file will be in .php and not in .html but there are so many HTML tags to type. I even tried adding this setting in zen-coding.sublime.settings and saved it in user folder but nothing happened. Why won't it work? This is where I got the reference from link, however its used in Zen Coding.js but the syntax are the same even in ST2. The Snippets are just additional settings but the main things is HTML zen-coding abbreviations won't appear in .php file but its working in .html. Anybody can solve this?

"my_zen_settings" : {
    "html": {
        "filters": "php,html",
        "abbreviations": {
            "jq": "<script src='jquery.js' type='javascript'>",
            "demo": "<div id=\"demo\"></div>"
        }
    },
    "css": {
        "filters": "html,css,fc",
        "snippets": {
            "c": "color:#${1:000000};"
        }
    },
    "php": {
       "filters": "php,html",
       "snippets": {
            "php":          "<?php | ?>",
            "php:info":     "<?php\nphpinfo();\n?>",
            "php:echo":     "<?php echo | ?>",

            "php:Ns":       "<?php\nnamespace |;\n\t\n?>",
            "php:ns":       "namespace |;",

            "php:Class":    "<?php\nclass |\n{\n\t\n}\n?>",
            "php:class":    "class |\n{\n\t\n}",

            "php:Function": "<?php\nfunction |() {\n\t\n}\n?>",
            "php:function": "function |() {\n\t\n}",

            "php:Var":      "<?php $| = ; ?>",
            "php:var":      "$| = ;",

            "php:Object":   "<?php $| = (object) ; ?>",
            "php:object":   "$| = (object) ;",

            "php:New":      "<?php $| = new ; ?>",
            "php:new":      "$| = new ;",

            "php:Bool":     "<?php $| = FALSE; ?>",
            "php:bool":     "$| = FALSE;",

            "php:Array":    "<?php $| = array(); ?>",
            "php:array":    "$| = array();",


            "php:Array+":   "<?php |[] = ; ?>",
            "php:array+":   "|[] = ;",

            "php:Array-":   "<?php unset($|[]); ?>",
            "php:array-":   "unset($|[]);",

                        //hack $|, seems to replace $i with $1
            "php:For":      "<?php\nfor ($|i = 0; $|i < |; $|i++) {\n\t\n}\n?>",
            "php:for":      "for ($|i = 0; $|i < |; $|i++) {\n\t\n}",

            "php:Foreach":  "<?php\nforeach (| as ) {\n\t\n}\n?>",
            "php:foreach":  "foreach (| as ) {\n\t\n}",

            "php:While":    "<?php\nwhile(|) {\n\t\n}\n?>",
            "php:while":    "while(|) {\n\t\n}",

            "php:Dowhile":  "<?php\ndo {\n\t\n} while(|);\n?>",
            "php:dowhile":  "do {\n\t\n} while(|);",

            "php:If":       "<?php if( | ) { ?>\n\t\n<?php }?>",
            "php:if":       "if( | ) {\n\t\n}",

            "php:Ifelse":   "<?php if( | ) { ?>\n\t\n<?php } else { ?>\n\t\n<?php }?>",
            "php:ifelse":   "if( | ) {\n\t\n} else {\n\t\n}",

            "php:Switch":   "<?php switch( | ) { \n\tcase :\n\t\t\n\t\tbreak;\n\tdefault :\n\t\t\n\t\tbreak;\n}\n?>",
            "php:switch":   "switch( | ) { \n\tcase :\n\t\t\n\t\tbreak;\n\tdefault :\n\t\t\n\t\tbreak;\n}",

            "php:Include":  "<?php include \"|\"; ?>",
            "php:include":  "include \"|\";",

            "php:Include1": "<?php include_once \"|\"; ?>",
            "php:include1": "include_once \"|\";"
        }
    }
}

Upvotes: 2

Views: 3619

Answers (3)

Vinay Raghu
Vinay Raghu

Reputation: 1279

adding text.php to Default (Windows).sublime-keymap worked for me.

Upvotes: 0

Hello World
Hello World

Reputation: 43

You can install Emmet for Sublime Text 2: https://github.com/sergeche/emmet-sublime

Notice : Emmet (ex-Zen Coding).

Upvotes: 1

Gilles
Gilles

Reputation: 31

had the same problem. Tried the following :

  1. preferences > browse package > Default (OSX).sublime-keymap
  2. found the "operand" index where "keys" = ctrl + alt + enter
  3. added "text.php" to that string. like this : "source.css - source.css.embedded, text.xml, text.html -source -meta.tag, meta.scope.between-tag-pair.html -source , text.php"

That seemed to do the trick. I hope this helps.

Upvotes: 3

Related Questions