8000 Rendering partial views via ajax · Issue #24 · ccampbell/sonic · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Rendering partial views via ajax #24
Open
@gordyr

Description

@gordyr

I'm attempting to render single view or turbo fragment on demand so that I am not re-rendering the full layout/page when it isn't necessary.

So far I have set up the following:-

Lets image I am currently at www.example.com

I click a link and rather than reload the whole page an ajax request is sent to www.example.com/home

this is routed to /ajax/home (and the full page including layout is routed to /home)

What I would like to do is extract the html (and css/js set in the view) and return it via JSON.

I am trying to do the following:

public function home()
{

}

public function ajaxhome()
{

    $this->setView('home');       
    $this->disableLayout();


}

This sends back the html which I can then replace an element with. Great.

However I want to put this html into a json array so that I can also collect the relevant css and javascript:-

public function ajaxhome()
{

    $this->setView('home');       
    $this->disableLayout();
    $test = $this->view->getHtml();

    $output = array(
                 'html' => $test
                );

    echo json_encode($output);

}

But it doesn't work. result['html'] is always null. Where am I going wrong?

Even if I get this working I still need to collect the css/JS so what I would really like to do is be able to built a full turbo fragment on demand.

Is there any way this can be achieved?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0