Skip to content

Question about Templates #382

@eugene-brit

Description

@eugene-brit

Hi, guys!

I've a problem with creating templates.

At first, I've created .docx file which contains this structure:

${clone}
${name}
${phone}
${email}
${/clone}

Then, I should clone content between ${clone} and ${/clone}. I use $document->cloneBlock('clone', 3); for it but nothing happens. When I open this generated file I see the same structure.

${clone}
${name}
${phone}
${email}
${/clone}

Could you help me? What should I do to clone this block?

And one more question. Can I use variables in the cloned block more than one time, somethings like this:

$document->setValue('name#1', 'Name 1');
$document->setValue('name#2', 'Name 2');

Best regards, Eugene


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Activity

franzholz

franzholz commented on Sep 24, 2014

@franzholz

The example "vendor/phpoffice/phpword/samples/Sample_07_TemplateCloneRow.php" answers your questions.

eugene-brit

eugene-brit commented on Sep 24, 2014

@eugene-brit
Author

I've seen this examle. But in this example says about table rows and I've asked about "text blocks".

rando85

rando85 commented on Nov 4, 2014

@rando85

I think the problem is with Word, if you check the xml code you can notice the vars are not saved as well, Word insert many tags between the name of your var and the ${ }

You can try deleting and retyping the tags but the setValue won't help you.

chc88

chc88 commented on Nov 12, 2014

@chc88
Contributor

See this issue: #341

My fix for the cloneBlock also includes the addition of _1 and _2 to variables within the cloned block

github-actions

github-actions commented on Nov 18, 2022

@github-actions

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @rando85@Progi1984@eugene-brit@franzholz@chc88

        Issue actions

          Question about Templates · Issue #382 · PHPOffice/PHPWord