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

Cannot save template on page editor #24

Closed
wpplumber opened this issue Apr 3, 2020 · 9 comments
Closed

Cannot save template on page editor #24

wpplumber opened this issue Apr 3, 2020 · 9 comments
Labels
support Helping people to figure out things

Comments

@wpplumber
Copy link

I had the template save operation working before while using an OOP architecture but when I moved the plugin code to this WP boilerplate I got the following message error!

image

Is it something with permission? I used the following route for backoffice page.

$router
	->register_route_of_type( ROUTE_TYPE::ADMIN)//ADMIN_WITH_POSSIBLE_AJAX )
	->with_controller( 'Admin_Settings@register_hook_callbacks' ) 
	->with_model( 'Admin_Settings' ) 
	->with_view( 'Admin_Settings' ); 
@sumitpore
Copy link
Owner

Inside register_hook_callbacks of Admin_Settings controller, you can add your own add_action and add_filter calls.

@wpplumber
Copy link
Author

wpplumber commented Apr 12, 2020

I did, but when accessing the page which should use the custom template it doesn't show and seems using the theme template?

@wpplumber
Copy link
Author

should it be something on locate_template()? any wiki in case you're busy?

@sumitpore
Copy link
Owner

I have not created a separate wiki for it. For Frontend related activities, ideally a separate controller should be created and that should be hooked on ROUTE_TYPE::FRONTEND Router. I suppose as of now you have created a single controller and have added everything into it. You can try replacing ROUTE_TYPE::ADMIN with ROUTE_TYPE::ANY in routes.php & see if it works.

If that does not work too, please provide me a psuedo code which worked w/o MVC.

@wpplumber
Copy link
Author

$router
	->register_route_of_type(ROUTE_TYPE::FRONTEND)
	->with_controller('Dashboard@register_hook_callbacks')
	->with_model('Dashboard')
	->with_view('Dashboard');

Result:
image

$router
	->register_route_of_type(ROUTE_TYPE::ANY)
	->with_controller('Dashboard@register_hook_callbacks')
	->with_model('Dashboard')
	->with_view('Dashboard');

image

@sumitpore
Copy link
Owner

sumitpore commented Apr 14, 2020

With ROUTE_TYPE::ANY, full class name (including namespace) should be passed to with_controller, with_model and with_view.

@sumitpore sumitpore added the support Helping people to figure out things label Apr 14, 2020
@wpplumber
Copy link
Author

I was able to see the template called in debug mode after adding the following to /core/class-view.php

$template =  $template_path .  $template_name; // To test
		// Get default template.
		if ( ! $template ) {
			$template = $default_path . $template_name;
		}

Do you use a solution for pages using custom template to manage them since you use the following:

public static function render_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
		if ( $args && is_array( $args ) ) {
			extract( $args ); // @codingStandardsIgnoreLine.
		}

		$located = static::locate_template( $template_name, $template_path, $default_path );
		if ( false == $located ) {
			return;
		}

		ob_start();
		do_action( 'plugin_name_before_template_render', $template_name, $template_path, $located, $args );
		include( $located );
		do_action( 'plugin_name_after_template_render', $template_name, $template_path, $located, $args );

		return ob_get_clean(); // @codingStandardsIgnoreLine.
	}

@wpplumber
Copy link
Author

wpplumber commented Apr 15, 2020

Using the following hook related to template within the controller of that permalink fixed the issue to load the custom template.

	public function register_hook_callbacks(){
					// Enqueue Styles & Scripts.
					add_action( 'wp_enqueue_scripts', 
					array( $this, 'enqueue_scripts' ) );
		
add_filter('template_include', 
	array( $this, 'view_project_template') 
);
	}

@wpplumber
Copy link
Author

thank you @sumitpore for this work repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Helping people to figure out things
Projects
None yet
Development

No branches or pull requests

2 participants