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

Possible Restriction Solution: custom templates must be defined in vendor atk4/ui #625

Closed
gowrav-vishwakarma opened this issue Dec 29, 2018 · 0 comments · Fixed by #628
Closed
Assignees

Comments

@gowrav-vishwakarma
Copy link
Collaborator

gowrav-vishwakarma commented Dec 29, 2018

ui/src/App.php

Line 424 in fa52a36

public function loadTemplate($name)

Suggested Code is

    public function loadTemplate($name)
    {
        $template = new \atk4\ui\Template();
        $template->app = $this;
        if (in_array($name[0], ['.', '/', '\\']) || strpos($name, ':\\') !== false) {
            $template->load($name);
        } else {
        	if(is_array($this->template_dir)){
        		foreach ($this->template_dir as $td) {
        			if(file_exists($td.'/'.$name)){
			            $template->load($td.'/'.$name);
			            break;
        			}
        		}
        	}else{
	            $template->load($this->template_dir.'/'.$name);
        	}
        }

        return $template;
    }

user class can override this class variable as


namespace your\namespace;

class App extends \atk4\ui\App {
    use \atk4\core\SessionTrait;
    use \atk4\core\NameTrait;
...

    public function __construct($defaults = [])
	{
		parent::__construct($defaults);
		$this->template_dir = [
			getcwd().'/../vendor/atk4/ui/template/'.$this->skin,
			getcwd().'/template',
		];
	}

here we have defined paths from our working directory location that is "DocumentRoot/admin" and vendor is in parent directory but user can define as per their need.

The path elements sequence defined precedence here

By this way, $this->template_dir can be override in User App class with array and user can create custom templates anywhere.

@gowrav-vishwakarma gowrav-vishwakarma changed the title custom template must be defined in vendor atk4/ui due to this Possible Restriction Solution: custom templates must be defined in vendor atk4/ui Dec 30, 2018
@DarkSide666 DarkSide666 self-assigned this Jan 5, 2019
DarkSide666 added a commit that referenced this issue Jan 5, 2019
…ectories

* Implement Template->tryLoad()
* fix #625
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants