T4 output filename - t4

How can i use generated file's name in template?
I'd like to something like this:
// This file: <#= OutputFileName #> was autogenerated
How can i do that in T4 or in T4Toolbox?

This seemed like something that should be as simple as reading a property but after reflecting over the Host variable and disassembling the text generator code I think the simplest way of doing this is:
<## template language="C#" hostspecific="true" #>
<## import namespace="System.IO" #>
// <#=Path.ChangeExtension (Host.TemplateFile, "cs")#>

It better to define it as a directive
for example for a xaml file
<## output extension="xaml" #>
or for txt
<## output extension=".txt" #>

Related

Separate main files in SCSS result in undefined variables

I'm basically doing a "theme" over existing scss by changing some variable definitions. I need to have separate css bundles rendered with different variables. I thought of having separate main files that import the common files to keep it DRY.
File structure
- variables_1.scss
- variables_2.scss
- main_1.scss
- main_2.scss
- _main-shared.scss
_main-shared.scss contains #import statements for all other scss files, but does not import variables.
Main file contents:
//main_1.scss
#use 'variables_1' as *;
#import "main-shared";
//main_2.scss
#use 'variables_2' as *;
#import "main-shared";
But multi-level imports do not seem to work resulting in SassError:
Undefined variable in _main-shared.scss.
Is there a better way to do this? I cannot import variables in _main-shared.scss since it would defeat the purpose of having separate variable files.
Is there a fix for this that I am not aware of or a better solution?

How I use a T4 template file in another T4 file

I have a file with t4 code, but I want to separate it into 2 files, how I do a include tt file in my tt file?
Try the include directive in Microsoft docs

How to call a static block of magento extension in .phtml file?

I have installed an extension for slider on my home page. It has given me a static block code.
Call via block:
{{block type="responsivebannerslider/index" name="responsivebannerslider_index" template="responsivebannerslider/index.phtml"}}
Dont know how call it in .phtml file?
You can call it from your template by creating a block on the layout directly in the phtml template file:
<?php echo $this->getLayout()->createBlock('responsivebannerslider/index')->setTemplate('responsivebannerslider/index.phtml')->toHtml(); ?>
Or if the block is listed in the extensions layout XML file, (which would be nested within a reference node), and would look something like:
<block type="responsivebannerslider/index" name="responsivebannerslider_index" as="an_alias" template="responsivebannerslider/index.phtml">
<label>Responsive banner</label>
</block>
And you'd call that in your template file like:
<?php echo $this->getChildHtml('an_alias'); ?>
<?php echo $this->getLayout()->createBlock('responsivebannerslider/index')->setTemplate('responsivebannerslider/index.phtml')->toHtml(); ?>

Change some fields in a file

I need to analyses a file and change some fields.
Example:
<taskdef uri="xxxxxx" resource="/mnt/data/yyy.xml">
<classpath path="/mnt/data/test.jar"/>
</taskdef>
<target name="test"
description="this is a xml file">
<fileset dir="/tmp/data/output/test_1/" includes=all/>
In my case I need to find this part:
<fileset dir="/tmp/data/output/test_1/" includes=all/>
and change just the name (for example) test_1
At the end, save the file
In your comment you say you "cannot use libraries like Nogokiri to parse the file". So I can only guess you're not doing full XML parsing.
Assuming you do not have to parse XML you could just use Ruby's String.replace method on the line in question. Just iterate over the lines in the file until you get to the one in quesion and call replace. Here's some pseudocode.
open file
for each line
is this what I want to change
change line
save (new) file

Using Gumby, when I import a new custom scss file into gumby.scss, do I include an underscore?

I noticed that in the gumby.scss file, there is the line:
#import "custom";
... but the filename itself is _custom.scss.
For every file that I create after that, do I include the underscore?
As an example, if I create a file _custom2.scss, would I then use the import
#import "custom2";
or
#import "_custom2":
?
If it assumes that there will be an underscore in the file name, what are the rules for its assumptions? Does it do that with all filenames?
You can use either.
A file that begins with an _ is a partial in Sass.
Basically, if you want it to generate its own css file, don't add the underscore. If you want to import it into another sass file, use the _.

Resources