Phoenix.View.render_existing/3

Parsed documentation:
View on GitHub
Renders a template only if it exists.

Same as `render/3`, but returns `nil` instead of raising.
Useful for dynamically rendering templates in the layout that may or
may not be implemented by the `@inner` view.

## Examples

Consider the case where the application layout allows views to dynamically
render a section of script tags in the head of the document. Some views
may wish to inject certain scripts, while others will not.

    <head>
      <%= render_existing view_module(@conn), "scripts.html", assigns %>
    </head>

Then the module for the `@inner` view can decide to provide scripts with
either a precompiled template, or by implementing the function directly, ie:

    def render("scripts.html", _assigns) do
      "<script src="...">"
    end

To use a precompiled template, create a `scripts.html.eex` file in the `templates`
directory for the corresponding view you want it to render for. For example,
for the `UserView`, create the `scripts.html.eex` file at `web/templates/user/`.

## Rendering based on controller template

In some cases, you might need to render based on the template from the controller.
For these cases, `Phoenix.Controller.controller_template/1` can pair with
`render_existing/3` for per-template based content, ie:

    <head>
      <%= render_existing view_module(@conn), "scripts." <> controller_template(@conn), assigns %>
    </head>

    def render("scripts.show.html", _assigns) do
      "<script src="...">"
    end
    def render("scripts.index.html", _assigns) do
      "<script src="...">"
    end
Suggestions:
Please help! Open an issue on GitHub if this assessment is incorrect.