Different code style settings in PhpStorm for php files based on file extension? - phpstorm

I'm using PhpStorm (and love it!), but the coding standard for my current project uses 4 space indents for .php files and 2 space indents for template files (.phtml). The template files are traditional php and HTML. Our code implements a standard Zend Framwork MVC setup.
Is there a way to configure PhpStorm to use one set of code style settings for *.php files and a different set of code style settings for *.phtml files?
Setting::File Type didn't work
I've tried associating .phtml files with the HTML file type, but that causes me to lose ALL php language assistance (no PHP syntax highlighting, no code assist, etc.).
Settings::Template Data Languages didn't work
I also looked for a solution using the the Template Data Languages setting. I setup my .phtml files to the File Type HTML, but PHP isn't an available setting, so it appears there is no way to add php language support for HTML files.

AFAIK it is not possible.
If you want to have PHP support, file extension has to be associated with PHP file type. That's the only way to have PHP support as PHP is not injectable language in current PhpStorm version/implementation.
You may utilize TextMate bundles support plugin and install PHP supported highlighting there. This will allow to assign .phtml extension to another file type. The drawback is that you can only have one language highlighting .. so HTML will not be highlighted + no code completion for actual PHP (that's as far as my simple experiments went with other not-yet-supported languages).

Related

Why do we use file extensions if the content is just plain text?

From what I can see, a browser will display the information found both in .txt files or .html files, properly displaying html tags inside them. My g++ compiler won't stop segnaling errors in a .lua file containing lua code, but it will still try compiling it without caring about the extension, while the lua interpreter won't even open a .cpp file, even if I wrote a perfectly working lua program inside.
So why do we need file extensions if the content is in all cases text? As I said, I could write a C++ program in a file with an arbitrary extension and it will properly compile it, so what are extensions even for?
On many systems you can associate extensions with certain applications. For example a double click on a .cpp file will open it in a C++ IDE while a double click on a .txt file will open it in the default text editor.
Another example: Most text editors have syntax highlighting that depends on the extension.
There are probably many more cases where the extension is useful as an indicator for the file type. Of course this is nothing but a convention, but one that has been established for decades.

Can i put a .doc or .txt for displaying data in html

I just wonder if i can put a .doc or .txt files in the html instead of placing too much code in showing the data. I think that should be some method but i m not sure about it
You can put a direct URL to a .doc or .txt file on your server without even using HTML if that's most convenient. A browser will typically display .txt files right in the browser itself. A .doc file would likely be offered to store on disk so you can use a program like Word to view it.
If you are talking about embedding data into an existing HTML page there are ways to do so but it would require knowing more about your server. Are you using PHP to respond to requests?
You can use a number of methods to acheive this. Most commonly used are php includes if the server is capable of executing php scripts. Javascript is also commonly used and there are many examples of how to do this. This could also be achieved using SSI (server side include) but this method is not commonly used and requires renaming the file with .shtml extension
Hope this helps.

Can we create Joomla custom template with HTML

I'm new to Joomla.
I'm having a small doubt coming to creating Joomla templates. In the file structure provided by joomla I can see only index.php file. My doubt is can we create a Joomla template using HTML also. so that in the file structure it reads index.html.
Thanks in Advance and Merry Christmas.
It is important here to distinguish between "can" and "should" here. I believe you "can" make a template in an html file without losing all of the Joomla functionality because Joomla places modules using tags like <jdoc:include type="modules" name="user4" /> which it will parse. I'm not positive, but fairly certain that the template does require a php to bootstrap it, but you could just have the php file include the html you want to use. The major drawback is that you will be losing all of the php helper methods that Joomla makes available for you, like JURI::base() for dealing with paths for your scripts/css, etc.
You definitely should take advantage of Joomla's capabilities with php, so use the php file. If you want to include some html files into that document, that's just fine.
I don't think you can do that. The index.php file you are referring to is the root index file, while each template has its own index.php file inside their folder inside templates folder. For example templates/beez3/index.php Joomla includes the index.php file of the chosen template during it's execution cycle. Failing to find such a file it will fall back to a preinstalled template throwing an error: The template for this display is not available. Also the frontend requests start by loading the root index.php file first and then proceed to other calls and <jdoc:include type="component" /> won't load anything as it won't have any framework loaded or any joomla functionality at all. Finally no extension will work since they all require the _JEXEC constant to be defined as it's being defined in the root index.php file:
/**
* Constant that is checked in included files to prevent direct access.
* define() is used in the installation folder rather than "const" to not error for PHP 5.2 and lower
*/
define('_JEXEC', 1);
It must be written in php and you can certainly keep your theme that you created within the template folder, as for keeping .html you can always use htaccess to serve whichever extension you want.

How do I use the Perl Text-MediawikiFormat to convert mediawiki to xhtml?

On an Ubuntu platform, I installed the nice little perl script
libtext-mediawikiformat-perl - Convert Mediawiki markup into other text formats
which is available on cpan. I'm not familiar with perl and have no idea how to go about using this library to write a perl script that would convert a mediawiki file to an html file. e.g. I'd like to just have a script I can run such as
./my_convert_script input.wiki > output.html
(perhaps also specifying the base url, etc), but have no idea where to start. Any suggestions?
I believe #amon is correct that perl library I reference in the question is not the right tool for the task I proposed.
I ended up using the mediawiki API with the action="parse" to convert to HTML using the mediawiki engine, which turned out to be much more reliable than any of the alternative parsers I tried proposed on the list. (I then used pandoc to convert my html to markdown.) The mediawiki API handles extraction of categories and other metadata too, and I just had to append the base url to internal image and page links.
Given the page title and base url, I ended up writing this as an R function.
wiki_parse <- function(page, baseurl, format="json", ...){
require(httr)
action = "parse"
addr <- paste(baseurl, "/api.php?format=", format, "&action=", action, "&page=", page, sep="")
config <- c(add_headers("User-Agent" = "rwiki"), ...)
out <- GET(addr, config=config)
parsed_content(out)
}
The Perl library Text::MediawikiFormat isn't really intended for stand-alone use but rather as a formatting engine inside a larger application.
The documentation at CPAN does actually show a way how to use this library, and does note that other modules might provide better support for one-off conversions.
You could try this (untested) one-liner
perl -MText::MediawikiFormat -e'$/=undef; print Text::MediawikiFormat::format(<>)' input.wiki >output.html
although that defies the whole point (and customization abilities) of this module.
I am sure that someone has already come up with a better way to convert single MediaWiki files, so here is a list of alternative MediaWiki processors on the mediawiki site. This SO question coud also be of help.
Other markup languages, such as Markdown provide better support for single-file conversions. Markdown is especially well suited for technical documents and mirrors email conventions. (Also, it is used on this site.)
The libfoo-bar-perl packages in the Ubuntu repositories are precompiled Perl modules. Usually, these would be installed via cpan or cpanm. While some of these libraries do include scripts, most don't, and aren't meant as stand-alone applications.

Add programming language to gedit external tools?

The gedit external tools plugin allows tools to apply to only one or more of a predefined list of file types.
How do I define my own file types?
Could you be more specific? What language?
Do yo want to add support for another programming language in gtksourceview - maybe you want to add code snippets for this language?
If this language is already supported
Then you have to find the language description and mime type files and install them on your system. You'll find these embedded in plugins packages (example: Gmate).
Here's an example for YAML:
find the language description file (yml.lang) and copy it to your ~/.local/share/gtksourceview-2.0/language-specs/ directory
find the mime-type file (x-yaml.xml) and copy it to your ~/.local/share/mime/package/
restart gedit; this language should show up the language list; you can now add your own snippets!
If you can't find any resource for this language (is this a custom language?)
Well, you'll have to write the whole thing. The mime-type file is pretty basic (just mapping file extensions to your newly created mime-type).
But writing your own language file is not straightforward.
These links should be useful to that matter:
Gedit: writing your own language
gtksourceview: new language tutorial (with C)
gtksourceview: XML language file reference