Jump to content

Keep code highlighting working in your editor


pwired
 Share

Recommended Posts

Hi,

The more you generate and concatenate pieces of markup, the less code is still highlighted by the editor.
It doesn't matter what output strategy you work with, this problem stays the same.

I think wireRenderFile and $files->render() keep the most code highlighted in the editor.

Do you think that working with a MVC pattern will bring back better code highlighting in the editor ?

How do you guys keep code still highlighted in your editor ?

 

Link to comment
Share on other sites

I am using the Bluefish editor. The code highlighting is working perfectly when I code plane html or php.

But when these   .=  'code '  .   'code '  {  come in then I hardly have any code highlighting left.

I am switching to wireRenderFile and $files->render because then I can code with highlighted code

Link to comment
Share on other sites

1 hour ago, kongondo said:

Visual Studio Code (nor Sublime Text

I no longer use PHPStorm but it is also able to properly highlight concatenated strings of source code. So it depends on the capabilities of the IDE/code editor.

I simply use the alternative PHP syntax: http://www.brian2000.com/php/understanding-alternative-syntax-for-control-structures-in-php/ in which case highlighting is supported by all editors.

  • Like 1
Link to comment
Share on other sites

Maybe you want to paste code snippets and a screenshot to help us understand your problem better?

I'm using VSCode and it looks like this:

0FYdQeM.png

Another example with a multiline concatenated string:

CVKp3yf.png

And another one appending some infos to a rendered field value:

fhhSHXg.png

  • Like 1
Link to comment
Share on other sites

Hi bernhard,

Thanks for stepping in

Here php gets normally highlighted

ClipBoard-1.jpg.96aa5ea22d7bb3dcceb82db098cb5c4d.jpg

 

And selected in red when I put the cursor in front of a php tag

ClipBoard-1b.jpg.b99b884334e81457e12eed1c6913f85e.jpg

 

Here html format still gets highlighted but the php part turns green like normal text strings

ClipBoard-3.thumb.jpg.cc2453825c02a4ac7e3386ca7ed11876.jpg

 

Here both html format and php turns green and nothing gets selected in red when I put the cursor in front of a tag

ClipBoard-4.thumb.jpg.deeafcea14644d4c1242281196e6df9f.jpg

 

 

Link to comment
Share on other sites

I have seen this coding style in a basic-page.php file

 

$output .= '
    <div class="hero is-dark is-medium" id="intro" style="background-image: url('.$images[0].')">
        <div class="is-overlay is-blue"></div>
        <div class="hero-body has-text-centered">
            <h1 class="title is-1">
                <a href="'.$page->url.'">
                    '.$page->get('headline|title').' 
                </a>
            </h1>
            <p class="subtitle has-text-centered is-5">
                '.$page->textfield_html.'
            </p>
        </div>
    </div>
	';

 

The coding is vertically between the $output .= '   and  ';

This way you can use normal code indentation horizontally per line

What do you think ?

 

 

 

 

 

Link to comment
Share on other sites

46 minutes ago, pwired said:

Here html format still gets highlighted but the php part turns green like normal text strings

ClipBoard-3.thumb.jpg.cc2453825c02a4ac7e3386ca7ed11876.jpg

VSCode in my home.php template file (note the marked php start and end tag because I had my cursor there which is not visible in the pic):

XFbtSCA.png

49 minutes ago, pwired said:

Here both html format and php turns green and nothing gets selected in red when I put the cursor in front of a tag

ClipBoard-4.thumb.jpg.deeafcea14644d4c1242281196e6df9f.jpg

That's ok because the green parts are just strings for your IDE! Same with VSCode:

es6Phx8.png

23 minutes ago, pwired said:

I have seen this coding style in a basic-page.php file

 


$output .= '
    <div class="hero is-dark is-medium" id="intro" style="background-image: url('.$images[0].')">
        <div class="is-overlay is-blue"></div>
        <div class="hero-body has-text-centered">
            <h1 class="title is-1">
                <a href="'.$page->url.'">
                    '.$page->get('headline|title').' 
                </a>
            </h1>
            <p class="subtitle has-text-centered is-5">
                '.$page->textfield_html.'
            </p>
        </div>
    </div>
	';

 

The coding is vertically between the $output .= '   and  ';

This way you can use normal code indentation horizontally per line

What do you think ?

I think you should have a look at https://processwire.com/api/ref/files/render/g/

Take this example:

8RLobCH.png

And in your invoicetemplates.php file you could have clean code just like this:

HSxoSMc.png

Why not give VSCode a try? ? 

  • Like 2
Link to comment
Share on other sites

Thanks for posting back on this bernhard and the link to $files->render()
Yes with $files->render() I have at least the usual <?php echo between html tags

I like this coding style:

$var_topnavigation .= '<li><a href="' . $pages->get("/")->url . '"><img src="' . $homebutton->url . '"></a></li>' . "\n";

this way no <?php or <?php echo needed and you can normally use the html " quotes.

You are right, it is time to move over to a better editor. I haven't seen how VSC handles inserting your own code snippets
and editing directly online over FTP. I have seen a whole thread about VSC in dev talk so I will give it a try.

 

Link to comment
Share on other sites

6 minutes ago, pwired said:

I like this coding style:

$var_topnavigation .= '<li><a href="' . $pages->get("/")->url . '"><img src="' . $homebutton->url . '"></a></li>' . "\n";

I recently tend to do this, don't know about any best practises, though:

G2uMOsC.png

7 minutes ago, pwired said:

You are right, it is time to move over to a better editor. I haven't seen how VSC handles inserting your own code snippets
and editing directly online over FTP. I have seen a whole thread about VSC in dev talk so I will give it a try.

That's the only thing where I'm not 100% happy so far. The available plugins that I tried are all somewhat clumsy/bloated/complicated. When I need to edit files directly I browse my server with WinSCP and then I can just double-click the file and it opens in VSCode. I can then edit and save this file from inside VScode and it gets uploaded automatically. For all other edits I switched to a git-setup, so I don't need direct edit via FTP any more.

Meanwhile we also have Tracy+File Editor Panel for quick on-demand server edits.

  • Like 2
Link to comment
Share on other sites

1 hour ago, bernhard said:

That's the only thing where I'm not 100% happy so far.

This is the sole reason also I'm stuck in prehistoric emacs setup, to easily work on servers, always a command away from connecting to a server and opening a folder

OMG it's finally here!! Gonna try this ASAP.

 https://marketplace.visualstudio.com/items?itemName=Kelvin.vscode-sshfs#review-details

EDIT: OMG it works wonders, love this.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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