Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: add mechanism for adding our own dynamic variables to be used in customized templates #356

Closed
vesper8 opened this issue Dec 8, 2016 · 4 comments

Comments

@vesper8
Copy link
Contributor

vesper8 commented Dec 8, 2016

In GeneratorConfig.php at the bottom of the loadDynamicVariables function you have this

        $commandData->addDynamicVariable(
            '$API_PREFIX$',
            config('infyom.laravel_generator.api_prefix', 'api')
        );

        $commandData->addDynamicVariable(
            '$API_VERSION$',
            config('infyom.laravel_generator.api_version', 'v1')
        );

This is a useful way of adding new dynamic variables. I have added a few of them myself that I use in my customized stubs.

However this forces me to make edits inside of the /vendor folder which is bad practice.

Would it be possible to add an array "dynamic_variables" inside of laravel_generator.php and iterate through it in GeneratorConfig.php so that we could add our own dynamic variables via the configuration file?

Please and thank you :)

@mitulgolakiya
Copy link
Member

@vesper8 currently, there is no way to do this, I will take it in a queue and will add a support for it.

@thewebartisan7
Copy link
Contributor

This would be good idea. Any update on this?

@mitulgolakiya
Copy link
Member

There is no update on this. We will think to add it soon.

@mitulgolakiya mitulgolakiya self-assigned this Aug 8, 2020
@mitulgolakiya mitulgolakiya changed the title add mechanism for adding our own dynamic variables to be used in customized templates [Feature]: add mechanism for adding our own dynamic variables to be used in customized templates Jan 28, 2022
@mitulgolakiya mitulgolakiya removed their assignment Jan 28, 2022
mitulgolakiya added a commit that referenced this issue Aug 4, 2022
@mitulgolakiya mitulgolakiya self-assigned this Aug 4, 2022
@mitulgolakiya
Copy link
Member

Just added support for this in the latest version v5.3.0.

You can add dynamic variables to the generator config by calling addDynamicVariables method in the service provider's boot method. For e.g,

Add the following code in the AppServiceProvider boot method,

GeneratorConfig::addDynamicVariable('testVar', 'testVal');

Alternatively, you can add multiple variables as well by,

GeneratorConfig::addDynamicVariables(['testVar1' => 'testVal1', 'testVar2' => 'testVal2']);

Once variables are added, you can publish templates and then modify the view file to use the variable,

protected $dynamicVars = [
    'testVal' => '{{ $config->getDynamicVariable('testVar') }}',
];

As per the new release, $config is injected in every view stub file that the generator uses.

Let me know if any further explanations or suggestions are there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants