Thank you Daniel.
I was able to solve the problem in my case by creating my own util class in
the freemarker.core package inside my own project's source tree. This
allowed me to access the package-private deprecated methods that I believe
are used for <#nested> handling.

I plan to clean it up a bit and submit a PR once I have a moment away from
my current project. My thought is that even though this relies on
deprecated methods, those methods are required for <#nested> support so if
they are refactored in the future there will have to be similar
functionality supplied by the refactor. It should be simple to maintain my
PR in that case.

Here is a preview of what I have now. At a minimum it will need some
modifications to use the Freemarker logging system and I will need to find
an appropriate place for it in the existing source. Any thoughts
appreciated.

public static String getRawMacroContent(boolean trim) {
    log.trace("Getting Raw Macro Content");

    StringBuilder sb = new StringBuilder();

    Environment environment = Environment.getCurrentEnvironment();
    Macro.Context invokingMacroContext = environment.getCurrentMacroContext();
    TemplateObject callPlace = invokingMacroContext.callPlace;
    TemplateElement[] nestedContentBuffer = callPlace instanceof
TemplateElement ? ((TemplateElement) callPlace).getChildBuffer() :
null;
    if (nestedContentBuffer != null) {
        for (TemplateElement templateElement : nestedContentBuffer) {
            log.trace("templateElement = {}", templateElement);
            sb.append(templateElement.getSource());
        }
    }

    if(trim) {
        return sb.toString().trim();
    } else {
        return sb.toString();
    }
}



On Thu, Nov 2, 2023 at 10:51 AM Daniel Dekany <daniel.dek...@gmail.com>
wrote:

> Kind of a niche use case... I would prefer avoiding much complexity and
> backward compatibility burden for it. But, maybe it's actually already
> doable. See my answer on Stack Overflow.
>
> On Mon, Oct 30, 2023 at 6:57 PM Cavan Morris <cavanmor...@softcoil.com>
> wrote:
>
> > Hello All,
> > I am developing an internal content management system using freemarker
> > templates and have run across a speed bump I've detailed in
> > a stackoverflow question here:
> >
> >
> https://stackoverflow.com/questions/77390595/freemarker-how-to-get-unprocessed-content-of-custom-directive
> >
> > The long and short of it is that I would like to access the RAW,
> > unprocessed content of the <#nested/> tag in my macro. I've looked
> through
> > the source for a way to do this and haven't found one. If it exists
> > please let me know!
> >
> > If not, I think it would be very useful to add this feature. Perhaps
> > through a simple flag on the existing <#nested> tag? Perhaps with the
> > addition of a new <#nested_raw> tag?
> >
> > Please let me know if you have any questions or if there is a way that I
> > can help make this happen.
> >
> > Thank you!
> >
>
>
> --
> Best regards,
> Daniel Dekany
>

Reply via email to