Oddity in PHP Snippets


#1

Hey folks,

I recently switched to the fabulous Atom and came across a bug while porting my snippets manually.

I saw this topic: PHP Snippets not working
Followed the hints but there lays an oddity while working with different snippets.
I think it may be related to containing html tags within which the php blocks and code are placed.

For instance, this works:

'.text.html.php':
  'print constant':
    'prefix': 'printcons'
    'body': '<?php print $2 ; ?>'

and this doesn’t:

'.text.html.php':
  'wp pingback':
    'prefix': 'pingback'
    'body': '<?php bloginfo("pingback_url"); ?>'

I would be very much grateful if you can guide me to overcome this issue.
Many thanks in advance.


#2

Do you have both of those full blocks in your snippets.cson file? If so, see this FAQ:


#3

Thanks for your response but it didn’t help at all!


#4

So what does your snippets.cson contain in it exactly?


#5

It has got rather long but here’s a glimpse:


#6

If you take a look at the FAQ I linked above, CSON is analogous to JSON. This means that only the last .text.html.php section is the one that is used … it overwrites the previous ones. So in your example, you would need to change it to:

'.text.html.php':
  'wp get sidebar':
    'prefix': 'wpgs'
    'body': '<?php get_sidebar(); ?>'
  'wp get header':
    'prefix': 'wpgh'
    'body': '<?php get_header(); ?>'
  'wp get header':
    'prefix': 'wpgf'
    'body': '<?php get_footer(); ?>'

'.source.css':
  'wp style.css':
    'prefix': 'wpstylecss'
    'body': """
    """

#7

Oh thanks. It’s working just fine.
That was quite subtle btw.

A question, so from here on out do I have to insert all of my html/php snippets below this block without writing another .text.html.php ?


#8

Yes, that’s correct.